Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iines #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ group :development, :test do
gem 'pry-byebug'
gem "binding_of_caller"
gem 'meta_request'
gem 'rspec-rails', '~> 3.0.0.beta', github: 'rspec/rspec-rails'
gem 'rspec-core', '~> 3.0.0.beta', github: 'rspec/rspec-core'
gem 'rspec-expectations', '~> 3.0.0.beta', github: 'rspec/rspec-expectations'
gem 'rspec-mocks', '~> 3.0.0.beta', github: 'rspec/rspec-mocks'
gem 'rspec-support', '~> 3.0.0.beta', github: 'rspec/rspec-support'
gem 'rspec', '~> 3.0.0.beta2', github: 'rspec/rspec'
gem 'rspec-rails', '~> 3.0.0.beta2', github: 'rspec/rspec-rails'
gem 'rspec-core', '~> 3.0.0.beta2', github: 'rspec/rspec-core'
gem 'rspec-expectations', '~> 3.0.0.beta2', github: 'rspec/rspec-expectations'
gem 'rspec-mocks', '~> 3.0.0.beta2', github: 'rspec/rspec-mocks'
gem 'rspec-support', '~> 3.0.0.beta2', github: 'rspec/rspec-support'
gem 'factory_girl_rails', '~> 4.4.1'
end

Expand All @@ -46,3 +47,12 @@ group :production do
gem 'pg'
gem 'rails_12factor'
end

group :development, :test do
gem 'spring'
gem 'spring-commands-rspec'
gem 'guard'
gem 'guard-bundler'
gem 'guard-rspec'
gem 'guard-livereload', require: false
end
71 changes: 62 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
GIT
remote: git://github.com/rspec/rspec-core.git
revision: 6b67068d1ae0525d15c02f3a1b00218e5b36b4db
revision: 17b5f7bdbfe961fbf30b44c408794b8ddb836ea5
specs:
rspec-core (3.0.0.beta2)
rspec-support (= 3.0.0.beta2)

GIT
remote: git://github.com/rspec/rspec-expectations.git
revision: 1603a39f45d6683b562ed91a5c766d83e2f3cb20
revision: d2bb4f609f74aebccebca49a3478c07a720ec92f
specs:
rspec-expectations (3.0.0.beta2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (= 3.0.0.beta2)

GIT
remote: git://github.com/rspec/rspec-mocks.git
revision: d2be1035a098b89d591d4573becae086452baf8c
revision: 98bab2457fd0d5ed799130c55dc5cf30815cbeff
specs:
rspec-mocks (3.0.0.beta2)
rspec-support (= 3.0.0.beta2)
Expand All @@ -37,10 +37,19 @@ GIT

GIT
remote: git://github.com/rspec/rspec-support.git
revision: 2d12b1e2368054cf9997fa2b2e41329769aa812d
revision: 454b0948685e1aace29e0e1828375ca121128da7
specs:
rspec-support (3.0.0.beta2)

GIT
remote: git://github.com/rspec/rspec.git
revision: c281bac1be86fd9e75a5a90b39107203305c9111
specs:
rspec (3.0.0.beta2)
rspec-core (= 3.0.0.beta2)
rspec-expectations (= 3.0.0.beta2)
rspec-mocks (= 3.0.0.beta2)

GEM
remote: https://rubygems.org/
remote: https://rails-assets.org/
Expand Down Expand Up @@ -86,6 +95,8 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
celluloid (0.15.2)
timers (~> 1.1.0)
cliver (0.3.2)
coderay (1.1.0)
coffee-rails (4.0.1)
Expand All @@ -103,15 +114,37 @@ GEM
dotenv (0.10.0)
dotenv-rails (0.10.0)
dotenv (= 0.10.0)
em-websocket (0.5.1)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
erb2haml (0.1.5)
html2haml
erubis (2.7.0)
eventmachine (1.0.3)
execjs (2.0.2)
factory_girl (4.4.0)
activesupport (>= 3.0.0)
factory_girl_rails (4.4.1)
factory_girl (~> 4.4.0)
railties (>= 3.0.0)
ffi (1.9.3)
formatador (0.2.4)
guard (2.6.1)
formatador (>= 0.2.4)
listen (~> 2.7)
lumberjack (~> 1.0)
pry (>= 0.9.12)
thor (>= 0.18.1)
guard-bundler (2.0.0)
bundler (~> 1.0)
guard (~> 2.2)
guard-livereload (2.1.2)
em-websocket (~> 0.5)
guard (~> 2.0)
multi_json (~> 1.8)
guard-rspec (4.2.9)
guard (~> 2.1)
rspec (>= 2.14, < 4.0)
haml (4.1.0.beta.1)
tilt
haml-rails (0.5.3)
Expand All @@ -127,6 +160,7 @@ GEM
haml (>= 4.0.0.rc.1)
hpricot (~> 0.8.6)
ruby_parser (~> 3.1.1)
http_parser.rb (0.6.0)
i18n (0.6.9)
jbuilder (1.5.3)
activesupport (>= 3.0.0)
Expand All @@ -138,6 +172,11 @@ GEM
launchy (2.4.2)
addressable (~> 2.3)
libv8 (3.16.14.3)
listen (2.7.5)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
rb-inotify (>= 0.9)
lumberjack (1.0.5)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
Expand Down Expand Up @@ -209,6 +248,9 @@ GEM
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.3.1)
rb-fsevent (0.9.4)
rb-inotify (0.9.4)
ffi (>= 0.5.0)
ref (1.0.5)
rspec-collection_matchers (0.0.3)
rspec-expectations (>= 2.99.0.beta1)
Expand All @@ -224,6 +266,9 @@ GEM
shoulda-matchers (2.6.0)
activesupport (>= 3.0.0)
slop (3.5.0)
spring (1.1.2)
spring-commands-rspec (1.0.2)
spring (>= 0.9.1)
sprockets (2.11.0)
hike (~> 1.2)
multi_json (~> 1.0)
Expand All @@ -240,6 +285,7 @@ GEM
thor (0.19.1)
thread_safe (0.3.3)
tilt (1.4.1)
timers (1.1.0)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
Expand All @@ -265,6 +311,10 @@ DEPENDENCIES
dotenv-rails
erb2haml
factory_girl_rails (~> 4.4.1)
guard
guard-bundler
guard-livereload
guard-rspec
haml-rails
jbuilder (~> 1.2)
jquery-rails
Expand All @@ -281,13 +331,16 @@ DEPENDENCIES
rails (= 4.1.0)
rails-assets-bootstrap
rails_12factor
rspec-core (~> 3.0.0.beta)!
rspec-expectations (~> 3.0.0.beta)!
rspec-mocks (~> 3.0.0.beta)!
rspec-rails (~> 3.0.0.beta)!
rspec-support (~> 3.0.0.beta)!
rspec (~> 3.0.0.beta2)!
rspec-core (~> 3.0.0.beta2)!
rspec-expectations (~> 3.0.0.beta2)!
rspec-mocks (~> 3.0.0.beta2)!
rspec-rails (~> 3.0.0.beta2)!
rspec-support (~> 3.0.0.beta2)!
sass-rails (~> 4.0.0)
shoulda-matchers (~> 2.6.0)
spring
spring-commands-rspec
sqlite3
therubyracer
turbolinks
Expand Down
42 changes: 42 additions & 0 deletions Guardfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard :bundler do
watch('Gemfile')
# Uncomment next line if your Gemfile contains the `gemspec' command.
# watch(/^.+\.gemspec/)
end

guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
end

guard :rspec, cmd: 'bundle exec spring rspec' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }

# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }

# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }

# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }

# FactoryGirl
watch(%r{^spec/factories/(.+).rb$}) { |m| ["spec/controllers", "spec/requests"] }
end

3 changes: 3 additions & 0 deletions app/assets/javascripts/iines.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
3 changes: 3 additions & 0 deletions app/assets/stylesheets/iines.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Place all the styles related to the iines controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
27 changes: 27 additions & 0 deletions app/controllers/iines_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class IinesController < ApplicationController
before_action :set_iine, only: [:destroy]

def index
end

def create
iine = Iine.new(iine_params)
iine.giver = current_user
iine.taker = iine.idea.user
iine.save
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

失敗した時の処理欲しいです

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここちょっと他の方の意見聞きたいのですが、savesave!のどっち使われてます? 自分は例外出したほうがトラブル避けやすいのでsave!使ってるんですが。

redirect_to :back
end

def destroy
@iine.destroy
end


def set_iine
@iine = Iine.find(parmas[:id])
end

def iine_params
params.require(:iine).permit(:idea_id)
end
end
2 changes: 2 additions & 0 deletions app/helpers/iines_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module IinesHelper
end
1 change: 1 addition & 0 deletions app/models/idea.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Idea < ActiveRecord::Base
has_many :comments
has_many :iines
belongs_to :user

validates :title, length: { maximum: 100 }, presence: true
Expand Down
5 changes: 5 additions & 0 deletions app/models/iine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Iine < ActiveRecord::Base
belongs_to :giver, class_name: 'User'
belongs_to :taker, class_name: 'User'
belongs_to :idea
end
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class User < ActiveRecord::Base
has_many :ideas
has_many :given_iines, class_name: 'Iine', foreign_key: :giver_id
has_many :taken_iines, class_name: 'Iine', foreign_key: :taker_id

def self.find_or_create_from_auth_hash(auth_hash)
provider = auth_hash[:provider]
Expand Down
3 changes: 3 additions & 0 deletions app/views/ideas/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.pull-right
= render 'iines/form', idea: @idea

%h1
= @idea.title

Expand Down
15 changes: 15 additions & 0 deletions app/views/iines/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
- if current_user.present?
- if idea.iines.where(giver_id: current_user.id).present?
%button.btn.btn-primary.btn-xs{disabled: "disabled"}
いいね
= idea.iines.count
- else
= form_for Iine.new(idea_id: idea.id), html: {class: 'form-inline'} do |f|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここはコントローラでIineをセットしてviewで呼び出した方が、MVC的に良い感じがします

= f.hidden_field :idea_id
%button.btn.btn-primary.btn-xs
いいね
= idea.iines.count
- else
%button.btn.btn-default.btn-xs{disabled: "disabled"}
いいね
= idea.iines.count
5 changes: 5 additions & 0 deletions app/views/iines/_iine.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%tr
%td= link_to iine.idea.title, iine.idea
%td= iine.giver.nickname
%td= iine.taker.nickname
%td= iine.created_at
2 changes: 2 additions & 0 deletions app/views/iines/create.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
%h1 Iines#create
%p Find me in app/views/iines/create.html.haml
2 changes: 2 additions & 0 deletions app/views/iines/destroy.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
%h1 Iines#destroy
%p Find me in app/views/iines/destroy.html.haml
7 changes: 7 additions & 0 deletions app/views/iines/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%h2 Taken
%table.table.table-bordered.table-condensed.table-hover= render current_user.taken_iines

%h2 Given
%table.table.table-bordered.table-condensed.table-hover= render current_user.given_iines


3 changes: 3 additions & 0 deletions app/views/layouts/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
.navbar-header
= link_to 'Design Beginners', root_path, class: 'navbar-brand'
#bs-example-navbar-collapse-1.collapse.navbar-collapse
%ul.nav.navbar-nav
- if logged_in?
%li= link_to 'いいね', iines_path
%ul.nav.navbar-nav.navbar-right
- if logged_in?
%li= link_to 'ログアウト', logout_path
Expand Down
2 changes: 2 additions & 0 deletions app/views/welcome/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@
= idea.title
- else
= idea.title
.pull-right
= render 'iines/form', idea: idea
4 changes: 4 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
APP_PATH = File.expand_path('../../config/application', __FILE__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 4 additions & 0 deletions bin/rake
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require_relative '../config/boot'
require 'rake'
Rake.application.run
7 changes: 7 additions & 0 deletions bin/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require 'bundler/setup'
load Gem.bin_path('rspec-core', 'rspec')
Loading