seems_rateable 1.0.13 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +20 -0
  3. data/Gemfile +3 -0
  4. data/README.md +41 -61
  5. data/Rakefile +8 -2
  6. data/app/assets/javascripts/seems_rateable/index.js +1 -0
  7. data/{lib/generators/seems_rateable/install/templates → app/assets/javascripts/seems_rateable}/jRating.js.erb +225 -225
  8. data/app/assets/stylesheets/seems_rateable/{application.css → index.css.erb} +2 -2
  9. data/app/controllers/seems_rateable/application_controller.rb +1 -3
  10. data/app/controllers/seems_rateable/rates_controller.rb +31 -0
  11. data/app/models/seems_rateable/rate.rb +2 -2
  12. data/bin/rails +8 -0
  13. data/config/routes.rb +1 -1
  14. data/lib/generators/seems_rateable/install/install_generator.rb +34 -28
  15. data/lib/generators/seems_rateable/install/templates/initializer.rb +5 -2
  16. data/lib/generators/seems_rateable/install/templates/rateable.js.erb +12 -22
  17. data/lib/generators/seems_rateable/install/templates/rates_migration.rb +6 -9
  18. data/lib/generators/seems_rateable/manifest_finder.rb +25 -0
  19. data/lib/generators/seems_rateable/migration_helpers.rb +21 -0
  20. data/lib/generators/seems_rateable/uninstall/templates/drop_seems_rateable_rates_table.rb +9 -0
  21. data/lib/generators/seems_rateable/uninstall/uninstall_generator.rb +50 -0
  22. data/lib/generators/seems_rateable/uninstall_old/templates/drop_seems_rateable_cached_ratings_table.rb +9 -0
  23. data/lib/generators/seems_rateable/uninstall_old/templates/drop_seems_rateable_rates_table.rb +9 -0
  24. data/lib/generators/seems_rateable/uninstall_old/uninstall_old_generator.rb +48 -0
  25. data/lib/seems_rateable.rb +22 -7
  26. data/lib/seems_rateable/builder.rb +35 -0
  27. data/lib/seems_rateable/builder/html_options.rb +37 -0
  28. data/lib/seems_rateable/configuration.rb +23 -0
  29. data/lib/seems_rateable/engine.rb +12 -7
  30. data/lib/seems_rateable/errors.rb +3 -17
  31. data/lib/seems_rateable/helpers/action_view_extension.rb +18 -0
  32. data/lib/seems_rateable/helpers/current_rater.rb +15 -0
  33. data/lib/seems_rateable/models/active_record_extension.rb +23 -0
  34. data/lib/seems_rateable/models/active_record_extension/rateable.rb +26 -0
  35. data/lib/seems_rateable/models/active_record_extension/rater.rb +11 -0
  36. data/lib/seems_rateable/rating.rb +19 -0
  37. data/lib/seems_rateable/routes.rb +1 -1
  38. data/lib/seems_rateable/version.rb +1 -1
  39. data/seems_rateable.gemspec +32 -0
  40. data/spec/builder_spec.rb +53 -0
  41. data/spec/controllers/rates_controller_spec.rb +56 -0
  42. data/spec/dummy/README.rdoc +28 -0
  43. data/spec/dummy/Rakefile +6 -0
  44. data/{app/assets/javascripts/seems_rateable → spec/dummy/app/assets/javascripts}/application.js +4 -3
  45. data/spec/dummy/app/assets/javascripts/posts.js +2 -0
  46. data/spec/dummy/app/assets/javascripts/rateable/rateable.js.erb +15 -0
  47. data/spec/dummy/app/assets/stylesheets/application.css +19 -0
  48. data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
  49. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  50. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  51. data/spec/dummy/app/controllers/posts_controller.rb +58 -0
  52. data/spec/dummy/app/models/.keep +0 -0
  53. data/spec/dummy/app/models/concerns/.keep +0 -0
  54. data/spec/dummy/app/models/post.rb +3 -0
  55. data/spec/dummy/app/models/user.rb +5 -0
  56. data/spec/dummy/app/views/layouts/application.html.erb +26 -0
  57. data/spec/dummy/app/views/posts/_form.html.erb +21 -0
  58. data/spec/dummy/app/views/posts/edit.html.erb +6 -0
  59. data/spec/dummy/app/views/posts/index.html.erb +28 -0
  60. data/spec/dummy/app/views/posts/new.html.erb +5 -0
  61. data/spec/dummy/app/views/posts/show.html.erb +9 -0
  62. data/spec/dummy/bin/bundle +3 -0
  63. data/spec/dummy/bin/rails +4 -0
  64. data/spec/dummy/bin/rake +4 -0
  65. data/spec/dummy/config.ru +4 -0
  66. data/spec/dummy/config/application.rb +42 -0
  67. data/spec/dummy/config/boot.rb +5 -0
  68. data/spec/dummy/config/database.yml +25 -0
  69. data/spec/dummy/config/environment.rb +5 -0
  70. data/spec/dummy/config/environments/development.rb +29 -0
  71. data/spec/dummy/config/environments/production.rb +80 -0
  72. data/spec/dummy/config/environments/test.rb +36 -0
  73. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  74. data/spec/dummy/config/initializers/devise.rb +254 -0
  75. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  76. data/spec/dummy/config/initializers/inflections.rb +16 -0
  77. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  78. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  79. data/spec/dummy/config/initializers/seems_rateable.rb +4 -0
  80. data/spec/dummy/config/initializers/session_store.rb +3 -0
  81. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  82. data/spec/dummy/config/locales/devise.en.yml +59 -0
  83. data/spec/dummy/config/locales/en.yml +23 -0
  84. data/spec/dummy/config/routes.rb +8 -0
  85. data/spec/dummy/db/migrate/20140506144141_create_posts.rb +9 -0
  86. data/spec/dummy/db/migrate/20140506144841_devise_create_users.rb +42 -0
  87. data/spec/dummy/db/migrate/20140520170316_create_seems_rateable_rates.rb +15 -0
  88. data/spec/dummy/db/schema.rb +54 -0
  89. data/spec/dummy/lib/assets/.keep +0 -0
  90. data/spec/dummy/public/404.html +58 -0
  91. data/spec/dummy/public/422.html +58 -0
  92. data/spec/dummy/public/500.html +57 -0
  93. data/spec/dummy/public/favicon.ico +0 -0
  94. data/spec/factories/posts.rb +5 -0
  95. data/spec/factories/rate.rb +7 -0
  96. data/spec/factories/users.rb +7 -0
  97. data/spec/features/rating_spec.rb +63 -0
  98. data/spec/helpers/action_view_extension_spec.rb +59 -0
  99. data/spec/models/active_record_extension_spec.rb +105 -0
  100. data/spec/models/rate_spec.rb +6 -0
  101. data/spec/rating_spec.rb +70 -0
  102. data/spec/spec_helper.rb +45 -0
  103. data/spec/support/dummies.rb +19 -0
  104. metadata +263 -25
  105. data/app/controllers/seems_rateable/ratings_controller.rb +0 -13
  106. data/app/models/seems_rateable/cached_rating.rb +0 -5
  107. data/lib/generators/seems_rateable/install/templates/cached_ratings_migration.rb +0 -17
  108. data/lib/seems_rateable/helpers.rb +0 -27
  109. data/lib/seems_rateable/model.rb +0 -91
@@ -0,0 +1,59 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ devise:
5
+ confirmations:
6
+ confirmed: "Your account was successfully confirmed."
7
+ send_instructions: "You will receive an email with instructions about how to confirm your account in a few minutes."
8
+ send_paranoid_instructions: "If your email address exists in our database, you will receive an email with instructions about how to confirm your account in a few minutes."
9
+ failure:
10
+ already_authenticated: "You are already signed in."
11
+ inactive: "Your account is not activated yet."
12
+ invalid: "Invalid email or password."
13
+ locked: "Your account is locked."
14
+ last_attempt: "You have one more attempt before your account will be locked."
15
+ not_found_in_database: "Invalid email or password."
16
+ timeout: "Your session expired. Please sign in again to continue."
17
+ unauthenticated: "You need to sign in or sign up before continuing."
18
+ unconfirmed: "You have to confirm your account before continuing."
19
+ mailer:
20
+ confirmation_instructions:
21
+ subject: "Confirmation instructions"
22
+ reset_password_instructions:
23
+ subject: "Reset password instructions"
24
+ unlock_instructions:
25
+ subject: "Unlock Instructions"
26
+ omniauth_callbacks:
27
+ failure: "Could not authenticate you from %{kind} because \"%{reason}\"."
28
+ success: "Successfully authenticated from %{kind} account."
29
+ passwords:
30
+ no_token: "You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided."
31
+ send_instructions: "You will receive an email with instructions on how to reset your password in a few minutes."
32
+ send_paranoid_instructions: "If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes."
33
+ updated: "Your password was changed successfully. You are now signed in."
34
+ updated_not_active: "Your password was changed successfully."
35
+ registrations:
36
+ destroyed: "Bye! Your account was successfully cancelled. We hope to see you again soon."
37
+ signed_up: "Welcome! You have signed up successfully."
38
+ signed_up_but_inactive: "You have signed up successfully. However, we could not sign you in because your account is not yet activated."
39
+ signed_up_but_locked: "You have signed up successfully. However, we could not sign you in because your account is locked."
40
+ signed_up_but_unconfirmed: "A message with a confirmation link has been sent to your email address. Please open the link to activate your account."
41
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
42
+ updated: "You updated your account successfully."
43
+ sessions:
44
+ signed_in: "Signed in successfully."
45
+ signed_out: "Signed out successfully."
46
+ unlocks:
47
+ send_instructions: "You will receive an email with instructions about how to unlock your account in a few minutes."
48
+ send_paranoid_instructions: "If your account exists, you will receive an email with instructions about how to unlock it in a few minutes."
49
+ unlocked: "Your account has been unlocked successfully. Please sign in to continue."
50
+ errors:
51
+ messages:
52
+ already_confirmed: "was already confirmed, please try signing in"
53
+ confirmation_period_expired: "needs to be confirmed within %{period}, please request a new one"
54
+ expired: "has expired, please request a new one"
55
+ not_found: "not found"
56
+ not_locked: "was not locked"
57
+ not_saved:
58
+ one: "1 error prohibited this %{resource} from being saved:"
59
+ other: "%{count} errors prohibited this %{resource} from being saved:"
@@ -0,0 +1,23 @@
1
+ # Files in the config/locales directory are used for internationalization
2
+ # and are automatically loaded by Rails. If you want to use locales other
3
+ # than English, add the necessary files in this directory.
4
+ #
5
+ # To use the locales, use `I18n.t`:
6
+ #
7
+ # I18n.t 'hello'
8
+ #
9
+ # In views, this is aliased to just `t`:
10
+ #
11
+ # <%= t('hello') %>
12
+ #
13
+ # To use a different locale, set it with `I18n.locale`:
14
+ #
15
+ # I18n.locale = :es
16
+ #
17
+ # This would use the information in config/locales/es.yml.
18
+ #
19
+ # To learn more, please read the Rails Internationalization guide
20
+ # available at http://guides.rubyonrails.org/i18n.html.
21
+
22
+ en:
23
+ hello: "Hello world"
@@ -0,0 +1,8 @@
1
+ Dummy::Application.routes.draw do
2
+ seems_rateable
3
+ resources :posts
4
+
5
+ devise_for :users
6
+
7
+ root to: "posts#index"
8
+ end
@@ -0,0 +1,9 @@
1
+ class CreatePosts < ActiveRecord::Migration
2
+ def change
3
+ create_table :posts do |t|
4
+ t.string :title
5
+
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,42 @@
1
+ class DeviseCreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table(:users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => false, :default => ""
6
+ t.string :encrypted_password, :null => false, :default => ""
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Rememberable
13
+ t.datetime :remember_created_at
14
+
15
+ ## Trackable
16
+ t.integer :sign_in_count, :default => 0, :null => false
17
+ t.datetime :current_sign_in_at
18
+ t.datetime :last_sign_in_at
19
+ t.string :current_sign_in_ip
20
+ t.string :last_sign_in_ip
21
+
22
+ ## Confirmable
23
+ # t.string :confirmation_token
24
+ # t.datetime :confirmed_at
25
+ # t.datetime :confirmation_sent_at
26
+ # t.string :unconfirmed_email # Only if using reconfirmable
27
+
28
+ ## Lockable
29
+ # t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
30
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
31
+ # t.datetime :locked_at
32
+
33
+
34
+ t.timestamps
35
+ end
36
+
37
+ add_index :users, :email, :unique => true
38
+ add_index :users, :reset_password_token, :unique => true
39
+ # add_index :users, :confirmation_token, :unique => true
40
+ # add_index :users, :unlock_token, :unique => true
41
+ end
42
+ end
@@ -0,0 +1,15 @@
1
+ class CreateSeemsRateableRates < ActiveRecord::Migration
2
+ def change
3
+ create_table :seems_rateable_rates do |t|
4
+ t.belongs_to :rater
5
+ t.belongs_to :rateable, polymorphic: true
6
+ t.float :stars, null: false
7
+ t.string :dimension
8
+ t.timestamps
9
+ end
10
+
11
+ add_index :seems_rateable_rates, :rater_id
12
+ add_index :seems_rateable_rates, [:rateable_id, :rateable_type]
13
+ add_index :seems_rateable_rates, :dimension
14
+ end
15
+ end
@@ -0,0 +1,54 @@
1
+ # encoding: UTF-8
2
+ # This file is auto-generated from the current state of the database. Instead
3
+ # of editing this file, please use the migrations feature of Active Record to
4
+ # incrementally modify your database, and then regenerate this schema definition.
5
+ #
6
+ # Note that this schema.rb definition is the authoritative source for your
7
+ # database schema. If you need to create the application database on another
8
+ # system, you should be using db:schema:load, not running all the migrations
9
+ # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
+ # you'll amass, the slower it'll run and the greater likelihood for issues).
11
+ #
12
+ # It's strongly recommended that you check this file into your version control system.
13
+
14
+ ActiveRecord::Schema.define(version: 20140520170316) do
15
+
16
+ create_table "posts", force: true do |t|
17
+ t.string "title"
18
+ t.datetime "created_at"
19
+ t.datetime "updated_at"
20
+ end
21
+
22
+ create_table "seems_rateable_rates", force: true do |t|
23
+ t.integer "rater_id"
24
+ t.integer "rateable_id"
25
+ t.string "rateable_type"
26
+ t.float "stars", null: false
27
+ t.string "dimension"
28
+ t.datetime "created_at"
29
+ t.datetime "updated_at"
30
+ end
31
+
32
+ add_index "seems_rateable_rates", ["dimension"], name: "index_seems_rateable_rates_on_dimension"
33
+ add_index "seems_rateable_rates", ["rateable_id", "rateable_type"], name: "index_seems_rateable_rates_on_rateable_id_and_rateable_type"
34
+ add_index "seems_rateable_rates", ["rater_id"], name: "index_seems_rateable_rates_on_rater_id"
35
+
36
+ create_table "users", force: true do |t|
37
+ t.string "email", default: "", null: false
38
+ t.string "encrypted_password", default: "", null: false
39
+ t.string "reset_password_token"
40
+ t.datetime "reset_password_sent_at"
41
+ t.datetime "remember_created_at"
42
+ t.integer "sign_in_count", default: 0, null: false
43
+ t.datetime "current_sign_in_at"
44
+ t.datetime "last_sign_in_at"
45
+ t.string "current_sign_in_ip"
46
+ t.string "last_sign_in_ip"
47
+ t.datetime "created_at"
48
+ t.datetime "updated_at"
49
+ end
50
+
51
+ add_index "users", ["email"], name: "index_users_on_email", unique: true
52
+ add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
53
+
54
+ end
File without changes
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/404.html -->
52
+ <div class="dialog">
53
+ <h1>The page you were looking for doesn't exist.</h1>
54
+ <p>You may have mistyped the address or the page may have moved.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,58 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/422.html -->
52
+ <div class="dialog">
53
+ <h1>The change you wanted was rejected.</h1>
54
+ <p>Maybe you tried to change something you didn't have access to.</p>
55
+ </div>
56
+ <p>If you are the application owner check the logs for more information.</p>
57
+ </body>
58
+ </html>
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style>
6
+ body {
7
+ background-color: #EFEFEF;
8
+ color: #2E2F30;
9
+ text-align: center;
10
+ font-family: arial, sans-serif;
11
+ }
12
+
13
+ div.dialog {
14
+ width: 25em;
15
+ margin: 4em auto 0 auto;
16
+ border: 1px solid #CCC;
17
+ border-right-color: #999;
18
+ border-left-color: #999;
19
+ border-bottom-color: #BBB;
20
+ border-top: #B00100 solid 4px;
21
+ border-top-left-radius: 9px;
22
+ border-top-right-radius: 9px;
23
+ background-color: white;
24
+ padding: 7px 4em 0 4em;
25
+ }
26
+
27
+ h1 {
28
+ font-size: 100%;
29
+ color: #730E15;
30
+ line-height: 1.5em;
31
+ }
32
+
33
+ body > p {
34
+ width: 33em;
35
+ margin: 0 auto 1em;
36
+ padding: 1em 0;
37
+ background-color: #F7F7F7;
38
+ border: 1px solid #CCC;
39
+ border-right-color: #999;
40
+ border-bottom-color: #999;
41
+ border-bottom-left-radius: 4px;
42
+ border-bottom-right-radius: 4px;
43
+ border-top-color: #DADADA;
44
+ color: #666;
45
+ box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
46
+ }
47
+ </style>
48
+ </head>
49
+
50
+ <body>
51
+ <!-- This file lives in public/500.html -->
52
+ <div class="dialog">
53
+ <h1>We're sorry, but something went wrong.</h1>
54
+ </div>
55
+ <p>If you are the application owner check the logs for more information.</p>
56
+ </body>
57
+ </html>
File without changes
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :post do
3
+ title "Awesome!"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :rate, class: SeemsRateable::Rate do
3
+ association :rateable, factory: :post
4
+ association :rater, factory: :user
5
+ stars { rand(1..5) }
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ FactoryGirl.define do
2
+ factory :user do
3
+ sequence :email do |i|
4
+ "person#{i}@guerrillamail.com"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,63 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'rating process', js: true do
4
+ let!(:post) { FactoryGirl.create(:post) }
5
+ let(:user) { FactoryGirl.create(:user) }
6
+ let(:div) { page.first('.rateable') }
7
+
8
+ include Warden::Test::Helpers
9
+ Warden.test_mode!
10
+
11
+ def login(user)
12
+ login_as(user, scope: :user, run_callbacks: false)
13
+ end
14
+
15
+ context "when can rate" do
16
+ before do
17
+ login(user)
18
+ end
19
+
20
+ it 'creates a new rate, updates the div and disables it' do
21
+ visit root_path
22
+
23
+ div.allow_reload!
24
+
25
+ old_body = page.body
26
+
27
+ old_average = div["data-average"]
28
+
29
+ div.click
30
+
31
+ expect(old_body).to_not equal(page.body)
32
+ expect(div.reload["data-average"]).to_not equal(old_average)
33
+ expect(div.reload["class"]).to include('jDisabled')
34
+ end
35
+ end
36
+
37
+ context "when cannot rate" do
38
+ shared_examples "doing nothing" do
39
+ it "does nothing" do
40
+ visit root_path
41
+
42
+ old_page = page
43
+
44
+ div.click
45
+
46
+ expect(old_page).to equal(page)
47
+ end
48
+ end
49
+
50
+ context "not logged in" do
51
+ it_behaves_like "doing nothing"
52
+ end
53
+
54
+ context "already rated" do
55
+ before do
56
+ FactoryGirl.create(:rate, rateable: post, rater: user)
57
+ login(user)
58
+ end
59
+
60
+ it_behaves_like "doing nothing"
61
+ end
62
+ end
63
+ end