From 3c65078acf7c666c1fae2791be05386678dfb3d7 Mon Sep 17 00:00:00 2001 From: willnet Date: Wed, 7 May 2014 15:22:25 +0900 Subject: [PATCH 01/13] Fix rougting bug that display 500 when 404 --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 63be4c0..b4c7ffc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -21,7 +21,7 @@ def authenticate redirect_to root_path, alert: 'ログインしてください' end - def error404(e) + def error404 render 'error404', status: 404, formats: [:html] end From e0508a863ee80a8a078ae5f6aec5c39fc9fe1d1c Mon Sep 17 00:00:00 2001 From: willnet Date: Wed, 7 May 2014 15:33:53 +0900 Subject: [PATCH 02/13] Bump up Rails to 4.1.1 --- Gemfile | 2 +- Gemfile.lock | 54 ++++++++++++++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Gemfile b/Gemfile index 827daf8..27b8373 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ ruby '2.1.1' source 'https://rubygems.org' source 'https://rails-assets.org' -gem 'rails', '4.1.0' +gem 'rails', '4.1.1' gem 'sass-rails', '~> 4.0.0' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0.0' diff --git a/Gemfile.lock b/Gemfile.lock index 4e81c56..5ac3db9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -45,27 +45,27 @@ GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ specs: - actionmailer (4.1.0) - actionpack (= 4.1.0) - actionview (= 4.1.0) + actionmailer (4.1.1) + actionpack (= 4.1.1) + actionview (= 4.1.1) mail (~> 2.5.4) - actionpack (4.1.0) - actionview (= 4.1.0) - activesupport (= 4.1.0) + actionpack (4.1.1) + actionview (= 4.1.1) + activesupport (= 4.1.1) rack (~> 1.5.2) rack-test (~> 0.6.2) - actionview (4.1.0) - activesupport (= 4.1.0) + actionview (4.1.1) + activesupport (= 4.1.1) builder (~> 3.1) erubis (~> 2.7.0) - activemodel (4.1.0) - activesupport (= 4.1.0) + activemodel (4.1.1) + activesupport (= 4.1.1) builder (~> 3.1) - activerecord (4.1.0) - activemodel (= 4.1.0) - activesupport (= 4.1.0) + activerecord (4.1.1) + activemodel (= 4.1.1) + activesupport (= 4.1.1) arel (~> 5.0.0) - activesupport (4.1.0) + activesupport (4.1.1) i18n (~> 0.6, >= 0.6.9) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) @@ -149,7 +149,7 @@ GEM mime-types (1.25.1) mini_portile (0.5.3) minitest (5.3.3) - multi_json (1.9.2) + multi_json (1.10.0) newrelic_rpm (3.8.0.218) nokogiri (1.6.1) mini_portile (~> 0.5.0) @@ -185,15 +185,15 @@ GEM rack (>= 0.9.1) rack-test (0.6.2) rack (>= 1.0) - rails (4.1.0) - actionmailer (= 4.1.0) - actionpack (= 4.1.0) - actionview (= 4.1.0) - activemodel (= 4.1.0) - activerecord (= 4.1.0) - activesupport (= 4.1.0) + rails (4.1.1) + actionmailer (= 4.1.1) + actionpack (= 4.1.1) + actionview (= 4.1.1) + activemodel (= 4.1.1) + activerecord (= 4.1.1) + activesupport (= 4.1.1) bundler (>= 1.3.0, < 2.0) - railties (= 4.1.0) + railties (= 4.1.1) sprockets-rails (~> 2.0) rails-assets-bootstrap (3.1.1) rails-assets-jquery (>= 1.9.0) @@ -203,9 +203,9 @@ GEM rails_stdout_logging rails_serve_static_assets (0.0.2) rails_stdout_logging (0.0.3) - railties (4.1.0) - actionpack (= 4.1.0) - activesupport (= 4.1.0) + railties (4.1.1) + actionpack (= 4.1.1) + activesupport (= 4.1.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.3.1) @@ -278,7 +278,7 @@ DEPENDENCIES pry pry-byebug pry-remote - rails (= 4.1.0) + rails (= 4.1.1) rails-assets-bootstrap rails_12factor rspec-core (~> 3.0.0.beta)! From 6b07f92200fee5606efd9a134698876950e7fe38 Mon Sep 17 00:00:00 2001 From: willnet Date: Wed, 7 May 2014 15:47:52 +0900 Subject: [PATCH 03/13] Add like model and migration --- app/models/comment.rb | 1 + app/models/idea.rb | 1 + app/models/like.rb | 3 +++ db/migrate/20140507063631_create_likes.rb | 12 ++++++++++++ db/schema.rb | 12 +++++++++++- spec/factories/favorites.rb | 9 +++++++++ spec/models/favorite_spec.rb | 5 +++++ 7 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 app/models/like.rb create mode 100644 db/migrate/20140507063631_create_likes.rb create mode 100644 spec/factories/favorites.rb create mode 100644 spec/models/favorite_spec.rb diff --git a/app/models/comment.rb b/app/models/comment.rb index a3d82d4..ffeb03e 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -1,4 +1,5 @@ class Comment < ActiveRecord::Base + has_many :likes, as: :likable belongs_to :idea belongs_to :user diff --git a/app/models/idea.rb b/app/models/idea.rb index bfdf8f2..55b8d4c 100644 --- a/app/models/idea.rb +++ b/app/models/idea.rb @@ -1,4 +1,5 @@ class Idea < ActiveRecord::Base + has_many :likes, as: :likable has_many :comments belongs_to :user diff --git a/app/models/like.rb b/app/models/like.rb new file mode 100644 index 0000000..3aa8722 --- /dev/null +++ b/app/models/like.rb @@ -0,0 +1,3 @@ +class Like < ActiveRecord::Base + belongs_to :likable, polymorphic: true +end diff --git a/db/migrate/20140507063631_create_likes.rb b/db/migrate/20140507063631_create_likes.rb new file mode 100644 index 0000000..8b6b582 --- /dev/null +++ b/db/migrate/20140507063631_create_likes.rb @@ -0,0 +1,12 @@ +class CreateLikes < ActiveRecord::Migration + def change + create_table :likes do |t| + t.integer :user_id, null: false + t.integer :likable_id, null: false + t.string :likable_type, null: false + t.timestamps + end + + add_index :likes, [:likable_id, :likable_type] + end +end diff --git a/db/schema.rb b/db/schema.rb index 58b5f42..818ad33 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140427143623) do +ActiveRecord::Schema.define(version: 20140507063631) do create_table "comments", force: true do |t| t.integer "idea_id" @@ -33,6 +33,16 @@ add_index "ideas", ["user_id"], name: "index_ideas_on_user_id" + create_table "likes", force: true do |t| + t.integer "user_id", null: false + t.integer "likable_id", null: false + t.string "likable_type", null: false + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "likes", ["likable_id", "likable_type"], name: "index_likes_on_likable_id_and_likable_type" + create_table "users", force: true do |t| t.string "provider", null: false t.string "uid", null: false diff --git a/spec/factories/favorites.rb b/spec/factories/favorites.rb new file mode 100644 index 0000000..9d366b7 --- /dev/null +++ b/spec/factories/favorites.rb @@ -0,0 +1,9 @@ +# Read about factories at https://github.com/thoughtbot/factory_girl + +FactoryGirl.define do + factory :favorite do + user_id 1 + target_id 1 + target_type "MyString" + end +end diff --git a/spec/models/favorite_spec.rb b/spec/models/favorite_spec.rb new file mode 100644 index 0000000..c029e13 --- /dev/null +++ b/spec/models/favorite_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe Favorite do + pending "add some examples to (or delete) #{__FILE__}" +end From 3f56532ec8cdd87a61cb7556a355cf7adda129dd Mon Sep 17 00:00:00 2001 From: willnet Date: Wed, 7 May 2014 15:57:03 +0900 Subject: [PATCH 04/13] Add likes_controller --- app/controllers/likes_controller.rb | 2 ++ app/helpers/likes_helper.rb | 2 ++ spec/controllers/likes_controller_spec.rb | 5 +++++ spec/helpers/likes_helper_spec.rb | 15 +++++++++++++++ 4 files changed, 24 insertions(+) create mode 100644 app/controllers/likes_controller.rb create mode 100644 app/helpers/likes_helper.rb create mode 100644 spec/controllers/likes_controller_spec.rb create mode 100644 spec/helpers/likes_helper_spec.rb diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb new file mode 100644 index 0000000..fbe2644 --- /dev/null +++ b/app/controllers/likes_controller.rb @@ -0,0 +1,2 @@ +class LikesController < ApplicationController +end diff --git a/app/helpers/likes_helper.rb b/app/helpers/likes_helper.rb new file mode 100644 index 0000000..a78a759 --- /dev/null +++ b/app/helpers/likes_helper.rb @@ -0,0 +1,2 @@ +module LikesHelper +end diff --git a/spec/controllers/likes_controller_spec.rb b/spec/controllers/likes_controller_spec.rb new file mode 100644 index 0000000..dd39280 --- /dev/null +++ b/spec/controllers/likes_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe LikesController do + +end diff --git a/spec/helpers/likes_helper_spec.rb b/spec/helpers/likes_helper_spec.rb new file mode 100644 index 0000000..483b20c --- /dev/null +++ b/spec/helpers/likes_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the LikesHelper. For example: +# +# describe LikesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +describe LikesHelper do + pending "add some examples to (or delete) #{__FILE__}" +end From 07ea6aaa886ab1eec36b482e20e22a946aa1841a Mon Sep 17 00:00:00 2001 From: willnet Date: Wed, 7 May 2014 16:41:23 +0900 Subject: [PATCH 05/13] Add quiet_assets --- Gemfile | 4 ++++ Gemfile.lock | 3 +++ 2 files changed, 7 insertions(+) diff --git a/Gemfile b/Gemfile index 27b8373..06c5833 100644 --- a/Gemfile +++ b/Gemfile @@ -34,6 +34,10 @@ group :development, :test do gem 'factory_girl_rails', '~> 4.4.1' end +group :development do + gem 'quiet_assets' +end + group :test do gem 'shoulda-matchers', '~> 2.6.0' gem 'capybara' diff --git a/Gemfile.lock b/Gemfile.lock index 5ac3db9..6c0e31e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -180,6 +180,8 @@ GEM pry-remote (0.1.8) pry (~> 0.9) slop (~> 3.0) + quiet_assets (1.0.2) + railties (>= 3.1, < 5.0) rack (1.5.2) rack-contrib (1.1.0) rack (>= 0.9.1) @@ -278,6 +280,7 @@ DEPENDENCIES pry pry-byebug pry-remote + quiet_assets rails (= 4.1.1) rails-assets-bootstrap rails_12factor From 44afd65f7112641ce550fe65d8222486b9723792 Mon Sep 17 00:00:00 2001 From: willnet Date: Wed, 7 May 2014 16:41:45 +0900 Subject: [PATCH 06/13] Add like function --- app/assets/javascripts/ideas.js.coffee | 5 +++++ app/controllers/likes_controller.rb | 15 +++++++++++++++ app/models/like.rb | 1 + app/views/ideas/show.html.haml | 7 +++++++ app/views/welcome/index.html.haml | 6 ++++++ config/routes.rb | 8 ++++++-- db/migrate/20140507063631_create_likes.rb | 1 + db/schema.rb | 1 + 8 files changed, 42 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/ideas.js.coffee b/app/assets/javascripts/ideas.js.coffee index 24f83d1..1b86163 100644 --- a/app/assets/javascripts/ideas.js.coffee +++ b/app/assets/javascripts/ideas.js.coffee @@ -1,3 +1,8 @@ # 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/ +# + +$(document).on 'ajax:success', '.js-like', (xhr, data, status) -> + location.reload() + diff --git a/app/controllers/likes_controller.rb b/app/controllers/likes_controller.rb index fbe2644..161c176 100644 --- a/app/controllers/likes_controller.rb +++ b/app/controllers/likes_controller.rb @@ -1,2 +1,17 @@ class LikesController < ApplicationController + before_action :authenticate + + def create + idea = Idea.find(params[:idea_id]) + comment_id = params[:comment_id] + + likable = if comment_id + idea.comments.find(comment_id) + else + idea + end + likable.likes.create!(user: current_user) + + head 201 + end end diff --git a/app/models/like.rb b/app/models/like.rb index 3aa8722..7ee0d62 100644 --- a/app/models/like.rb +++ b/app/models/like.rb @@ -1,3 +1,4 @@ class Like < ActiveRecord::Base + belongs_to :user belongs_to :likable, polymorphic: true end diff --git a/app/views/ideas/show.html.haml b/app/views/ideas/show.html.haml index 60f04d9..f680dcb 100644 --- a/app/views/ideas/show.html.haml +++ b/app/views/ideas/show.html.haml @@ -12,6 +12,13 @@ = comment.body - else = comment.body + .pull-right + イイネ!: #{comment.likes.count} + - if logged_in? && comment.likes.exists?(user: current_user) + = link_to 'イイネ!済み', '#', class: 'btn btn-primary btn-sm disabled' + - elsif logged_in? + = link_to 'イイネ!', idea_comment_likes_path(@idea, comment), method: :post, remote: true, class: 'btn btn-primary btn-sm js-like' + - if logged_in? = form_for [@idea, @comment] do |f| - if @comment.errors.any? diff --git a/app/views/welcome/index.html.haml b/app/views/welcome/index.html.haml index 2d0fc84..1d00455 100644 --- a/app/views/welcome/index.html.haml +++ b/app/views/welcome/index.html.haml @@ -29,3 +29,9 @@ = idea.title - else = idea.title + .pull-right + イイネ!: #{idea.likes.count} + - if logged_in? && idea.likes.exists?(user: current_user) + = link_to 'イイネ!済み', '#', class: 'btn btn-primary btn-sm disabled' + - elsif logged_in? + = link_to 'イイネ!', idea_likes_path(idea), method: :post, remote: true, class: 'btn btn-primary btn-sm js-like' diff --git a/config/routes.rb b/config/routes.rb index 8c94f3a..7d19ec9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -4,8 +4,12 @@ get '/auth/failure' => 'sessions#failure' get '/logout' => 'sessions#destroy', as: :logout - resources :ideas, only: [:show, :create] do - resources :comments, only: :create + concern :likable do + resources :likes, only: :create + end + + resources :ideas, concerns: :likable, only: [:show, :create] do + resources :comments, concerns: :likable, only: :create end match '*path' => 'application#error404', via: :all diff --git a/db/migrate/20140507063631_create_likes.rb b/db/migrate/20140507063631_create_likes.rb index 8b6b582..77d46b7 100644 --- a/db/migrate/20140507063631_create_likes.rb +++ b/db/migrate/20140507063631_create_likes.rb @@ -8,5 +8,6 @@ def change end add_index :likes, [:likable_id, :likable_type] + add_index :likes, [:user_id, :likable_id, :likable_type], unique: true end end diff --git a/db/schema.rb b/db/schema.rb index 818ad33..f6b3339 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -42,6 +42,7 @@ end add_index "likes", ["likable_id", "likable_type"], name: "index_likes_on_likable_id_and_likable_type" + add_index "likes", ["user_id", "likable_id", "likable_type"], name: "index_likes_on_user_id_and_likable_id_and_likable_type", unique: true create_table "users", force: true do |t| t.string "provider", null: false From 6621c180ed62fc530f6a6200d49383542ac9ac62 Mon Sep 17 00:00:00 2001 From: willnet Date: Wed, 7 May 2014 16:52:17 +0900 Subject: [PATCH 07/13] Delete favorite_spec.rb and add like_spec.rb --- spec/models/favorite_spec.rb | 5 ----- spec/models/like_spec.rb | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) delete mode 100644 spec/models/favorite_spec.rb create mode 100644 spec/models/like_spec.rb diff --git a/spec/models/favorite_spec.rb b/spec/models/favorite_spec.rb deleted file mode 100644 index c029e13..0000000 --- a/spec/models/favorite_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'spec_helper' - -describe Favorite do - pending "add some examples to (or delete) #{__FILE__}" -end diff --git a/spec/models/like_spec.rb b/spec/models/like_spec.rb new file mode 100644 index 0000000..ce06d89 --- /dev/null +++ b/spec/models/like_spec.rb @@ -0,0 +1,6 @@ +require 'spec_helper' + +describe Like do + it { should belong_to :user } + it { should belong_to :likable } +end From f1a64ad6d1d459a84c8b8515061fe1aa0a65770d Mon Sep 17 00:00:00 2001 From: willnet Date: Tue, 20 May 2014 14:11:59 +0900 Subject: [PATCH 08/13] Disable transactional fixtures because of using database_rewinder --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d09b020..fbd4451 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -36,7 +36,7 @@ # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. - config.use_transactional_fixtures = true + config.use_transactional_fixtures = false # Run specs in random order to surface order dependencies. If you find an # order dependency and want to debug it, you can fix the order by providing From 37f81434d4b4e403c69fa1601a4dbea3b36fdf37 Mon Sep 17 00:00:00 2001 From: willnet Date: Tue, 20 May 2014 14:13:07 +0900 Subject: [PATCH 09/13] Bump up ruby, rails and rspec --- Gemfile | 8 ++--- Gemfile.lock | 73 +++++++++++++-------------------------------- spec/spec_helper.rb | 2 ++ 3 files changed, 24 insertions(+), 59 deletions(-) diff --git a/Gemfile b/Gemfile index 06c5833..e35c167 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ -ruby '2.1.1' +ruby '2.1.2' source 'https://rubygems.org' source 'https://rails-assets.org' @@ -26,11 +26,7 @@ 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-rails', '~> 3.0.0.rc1' gem 'factory_girl_rails', '~> 4.4.1' end diff --git a/Gemfile.lock b/Gemfile.lock index 6c0e31e..6971b1b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,46 +1,3 @@ -GIT - remote: git://github.com/rspec/rspec-core.git - revision: 6b67068d1ae0525d15c02f3a1b00218e5b36b4db - specs: - rspec-core (3.0.0.beta2) - rspec-support (= 3.0.0.beta2) - -GIT - remote: git://github.com/rspec/rspec-expectations.git - revision: 1603a39f45d6683b562ed91a5c766d83e2f3cb20 - 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 - specs: - rspec-mocks (3.0.0.beta2) - rspec-support (= 3.0.0.beta2) - -GIT - remote: git://github.com/rspec/rspec-rails.git - revision: 3d63b16bc6d8f8cf6d605e1d62e940f8441d0cd7 - specs: - rspec-rails (3.0.0.beta2) - actionpack (>= 3.0) - activemodel (>= 3.0) - activesupport (>= 3.0) - railties (>= 3.0) - rspec-collection_matchers - rspec-core (= 3.0.0.beta2) - rspec-expectations (= 3.0.0.beta2) - rspec-mocks (= 3.0.0.beta2) - rspec-support (= 3.0.0.beta2) - -GIT - remote: git://github.com/rspec/rspec-support.git - revision: 2d12b1e2368054cf9997fa2b2e41329769aa812d - specs: - rspec-support (3.0.0.beta2) - GEM remote: https://rubygems.org/ remote: https://rails-assets.org/ @@ -148,8 +105,8 @@ GEM method_source (0.8.2) mime-types (1.25.1) mini_portile (0.5.3) - minitest (5.3.3) - multi_json (1.10.0) + minitest (5.3.4) + multi_json (1.10.1) newrelic_rpm (3.8.0.218) nokogiri (1.6.1) mini_portile (~> 0.5.0) @@ -210,10 +167,24 @@ GEM activesupport (= 4.1.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - rake (10.3.1) + rake (10.3.2) ref (1.0.5) - rspec-collection_matchers (0.0.3) - rspec-expectations (>= 2.99.0.beta1) + rspec-core (3.0.0.rc1) + rspec-support (= 3.0.0.rc1) + rspec-expectations (3.0.0.rc1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (= 3.0.0.rc1) + rspec-mocks (3.0.0.rc1) + rspec-support (= 3.0.0.rc1) + rspec-rails (3.0.0.rc1) + actionpack (>= 3.0) + activesupport (>= 3.0) + railties (>= 3.0) + rspec-core (= 3.0.0.rc1) + rspec-expectations (= 3.0.0.rc1) + rspec-mocks (= 3.0.0.rc1) + rspec-support (= 3.0.0.rc1) + rspec-support (3.0.0.rc1) ruby_parser (3.1.3) sexp_processor (~> 4.1) sass (3.2.19) @@ -284,11 +255,7 @@ DEPENDENCIES rails (= 4.1.1) 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-rails (~> 3.0.0.rc1) sass-rails (~> 4.0.0) shoulda-matchers (~> 2.6.0) sqlite3 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fbd4451..b64b929 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -65,4 +65,6 @@ config.after :each do DatabaseRewinder.clean end + + config.infer_spec_type_from_file_location! end From 2e616b9910846affdbda0ebb79c03e18ef022b42 Mon Sep 17 00:00:00 2001 From: willnet Date: Tue, 20 May 2014 14:17:54 +0900 Subject: [PATCH 10/13] Bump up travis ruby version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 68dd3c9..bc7dd1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby rvm: - - 2.1.1 + - 2.1.2 deploy: provider: heroku api_key: From 9f970ab1b1d07dc9b2b54fe82007317119e8669f Mon Sep 17 00:00:00 2001 From: willnet Date: Tue, 20 May 2014 15:15:55 +0900 Subject: [PATCH 11/13] Add feature specs of like --- spec/features/create_like_to_comment_spec.rb | 34 ++++++++++++++++++++ spec/features/create_like_to_idea_spec.rb | 34 ++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 spec/features/create_like_to_comment_spec.rb create mode 100644 spec/features/create_like_to_idea_spec.rb diff --git a/spec/features/create_like_to_comment_spec.rb b/spec/features/create_like_to_comment_spec.rb new file mode 100644 index 0000000..a98a486 --- /dev/null +++ b/spec/features/create_like_to_comment_spec.rb @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +require 'spec_helper' + +describe 'よいコメントに"イイネ!"をする' do + let(:comment) { create :comment } + + context '未ログイン状態でアイデアページにアクセスしたとき' do + before { visit idea_path(comment.idea) } + + it 'イイネ!ボタンが表示されていないこと' do + expect(page).to have_no_css '.btn.js-like' + end + end + + context 'ログイン状態でアイデアページにアクセスしたとき' do + before do + login + visit idea_path(comment.idea) + end + + it 'イイネ!ボタンが表示されていること' do + expect(find('.btn.js-like')).to have_content 'イイネ!' + end + + context 'かつ、イイネ!をクリックしたとき', js: true do + before { click_link 'イイネ!' } + + it '"イイネ!" が "イイネ!済み" になり、disabled になっていること' do + expect(page).to have_no_css '.btn.js-like' + expect(find('.btn.disabled')).to have_content 'イイネ!済み' + end + end + end +end diff --git a/spec/features/create_like_to_idea_spec.rb b/spec/features/create_like_to_idea_spec.rb new file mode 100644 index 0000000..28c34c9 --- /dev/null +++ b/spec/features/create_like_to_idea_spec.rb @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +require 'spec_helper' + +describe 'よいアイデアに"イイネ!"をする' do + before { create :idea } + + context '未ログイン状態でトップページにアクセスしたとき' do + before { visit root_path } + + it 'イイネ!ボタンが表示されていないこと' do + expect(page).to have_no_css '.btn.js-like' + end + end + + context 'ログイン状態でトップページにアクセスしたとき' do + before do + login + visit root_path + end + + it 'イイネ!ボタンが表示されていること' do + expect(find('.btn.js-like')).to have_content 'イイネ!' + end + + context 'かつ、イイネ!をクリックしたとき', js: true do + before { click_link 'イイネ!' } + + it '"イイネ!" が "イイネ!済み" になり、disabled になっていること' do + expect(page).to have_no_css '.btn.js-like' + expect(find('.btn.disabled')).to have_content 'イイネ!済み' + end + end + end +end From ad1741714fd758135657eafc8931a950eeacb5a4 Mon Sep 17 00:00:00 2001 From: willnet Date: Tue, 20 May 2014 15:16:31 +0900 Subject: [PATCH 12/13] Delete unnecessary factory file --- spec/factories/favorites.rb | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 spec/factories/favorites.rb diff --git a/spec/factories/favorites.rb b/spec/factories/favorites.rb deleted file mode 100644 index 9d366b7..0000000 --- a/spec/factories/favorites.rb +++ /dev/null @@ -1,9 +0,0 @@ -# Read about factories at https://github.com/thoughtbot/factory_girl - -FactoryGirl.define do - factory :favorite do - user_id 1 - target_id 1 - target_type "MyString" - end -end From a2d054477422d96b0d8f4139cfb7ba49db2930bd Mon Sep 17 00:00:00 2001 From: willnet Date: Tue, 20 May 2014 15:26:41 +0900 Subject: [PATCH 13/13] Add a badge of Code Climate to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cc5eeab..e6bb314 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # デザインビギナーズのアイデア帳 [![Build Status](https://travis-ci.org/design-beginners/debeg-idea.svg?branch=master)](https://travis-ci.org/design-beginners/debeg-idea) +[![Code Climate](https://codeclimate.com/github/design-beginners/debeg-idea.png)](https://codeclimate.com/github/design-beginners/debeg-idea) ## Setup for development