seems_rateable 1.0.13 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Dummy::Application.load_tasks
@@ -9,7 +9,8 @@
9
9
  //
10
10
  // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
-
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
13
15
  //= require_tree .
14
-
15
-
16
+ //= require seems_rateable
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ $(document).ready(function(){
2
+ $(".rateable").jRating({
3
+ //default options displayed below ->
4
+
5
+ rateMax: 5, //Maximal rate
6
+ length : 5, //Number of stars
7
+ //decimalLength : 0, //Number of decimals in the rate
8
+ //type : 'big', //Big or small
9
+ //step : true, //If set to true, filling of the stars is done star by star (step by step).
10
+ //isDisabled: false, //Set true to display static rating
11
+ //showRateInfo: true, //Rate info panel, set true to display
12
+ //rateInfosX : 45, //In pixel - Absolute left position of the information box during mousemove.
13
+ //rateInfosY : 5, //In pixel - Absolute top position of the information box during mousemove.
14
+ });
15
+ });
@@ -0,0 +1,19 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ *= require seems_rateable
14
+ */
15
+
16
+ .container {
17
+ width: 900px;
18
+ margin: 0 auto;
19
+ }
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,58 @@
1
+ class PostsController < ApplicationController
2
+ before_action :set_post, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /posts
5
+ def index
6
+ @posts = Post.all
7
+ end
8
+
9
+ # GET /posts/1
10
+ def show
11
+ end
12
+
13
+ # GET /posts/new
14
+ def new
15
+ @post = Post.new
16
+ end
17
+
18
+ # GET /posts/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /posts
23
+ def create
24
+ @post = Post.new(post_params)
25
+
26
+ if @post.save
27
+ redirect_to @post, notice: 'Post was successfully created.'
28
+ else
29
+ render action: 'new'
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /posts/1
34
+ def update
35
+ if @post.update(post_params)
36
+ redirect_to @post, notice: 'Post was successfully updated.'
37
+ else
38
+ render action: 'edit'
39
+ end
40
+ end
41
+
42
+ # DELETE /posts/1
43
+ def destroy
44
+ @post.destroy
45
+ redirect_to posts_url, notice: 'Post was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_post
51
+ @post = Post.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def post_params
56
+ params.require(:post).permit(:title)
57
+ end
58
+ end
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ class Post < ActiveRecord::Base
2
+ seems_rateable :speed, :quality, :price
3
+ end
@@ -0,0 +1,5 @@
1
+ class User < ActiveRecord::Base
2
+ devise :database_authenticatable, :registerable
3
+
4
+ seems_rateable_rater
5
+ end
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
6
+ <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
7
+ <%= csrf_meta_tags %>
8
+
9
+ </head>
10
+ <body>
11
+
12
+ <div class="container">
13
+ <%= link_to content_tag(:h1, "Dummy App"), root_url %>
14
+
15
+ <% if current_user %>
16
+ <%= current_user.email %>
17
+ <%= link_to "Logout", destroy_user_session_path, method: :delete %>
18
+ <% else %>
19
+ <%= link_to "Login", new_user_session_path %>
20
+ <% end %>
21
+
22
+ <%= yield %>
23
+ </div>
24
+
25
+ </body>
26
+ </html>
@@ -0,0 +1,21 @@
1
+ <%= form_for(@post) do |f| %>
2
+ <% if @post.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @post.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :title %><br>
16
+ <%= f.text_field :title %>
17
+ </div>
18
+ <div class="actions">
19
+ <%= f.submit %>
20
+ </div>
21
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing post</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @post %> |
6
+ <%= link_to 'Back', posts_path %>
@@ -0,0 +1,28 @@
1
+ <h1>Listing posts</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Title</th>
7
+ <th></th>
8
+ <th></th>
9
+ <th></th>
10
+ </tr>
11
+ </thead>
12
+
13
+ <tbody>
14
+ <% @posts.each do |post| %>
15
+ <tr>
16
+ <td><%= post.title %></td>
17
+ <td><%= link_to 'Show', post %></td>
18
+ <td><%= link_to 'Edit', edit_post_path(post) %></td>
19
+ <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
20
+ <td><%= rating_for post %></td>
21
+ </tr>
22
+ <% end %>
23
+ </tbody>
24
+ </table>
25
+
26
+ <br>
27
+
28
+ <%= link_to 'New Post', new_post_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New post</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', posts_path %>
@@ -0,0 +1,9 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Title:</strong>
5
+ <%= @post.title %>
6
+ </p>
7
+
8
+ <%= link_to 'Edit', edit_post_path(@post) %> |
9
+ <%= link_to 'Back', posts_path %>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run Rails.application
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ # Pick the frameworks you want:
4
+ require "active_record/railtie"
5
+ require "action_controller/railtie"
6
+ require "action_mailer/railtie"
7
+ require "sprockets/railtie"
8
+ # require "rails/test_unit/railtie"
9
+
10
+ Bundler.require(*Rails.groups)
11
+
12
+ require "seems_rateable"
13
+
14
+ require "devise"
15
+
16
+ module Dummy
17
+ class Application < Rails::Application
18
+ # Settings in config/environments/* take precedence over those specified here.
19
+ # Application configuration should go into files in config/initializers
20
+ # -- all .rb files in that directory are automatically loaded.
21
+
22
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
23
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
24
+ # config.time_zone = 'Central Time (US & Canada)'
25
+
26
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
27
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
28
+ # config.i18n.default_locale = :de
29
+
30
+ configure do
31
+ config.generators do |g|
32
+ g.factory_girl dir: '../../spec/factories'
33
+ g.view_specs false
34
+ g.helper_specs false
35
+ g.controller_specs false
36
+ g.model_specs false
37
+ g.request_specs false
38
+ g.routing_specs false
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)
@@ -0,0 +1,25 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ #
4
+ # Ensure the SQLite 3 gem is defined in your Gemfile
5
+ # gem 'sqlite3'
6
+ development:
7
+ adapter: sqlite3
8
+ database: db/development.sqlite3
9
+ pool: 5
10
+ timeout: 5000
11
+
12
+ # Warning: The database defined as "test" will be erased and
13
+ # re-generated from your development database when you run "rake".
14
+ # Do not set this db to the same as development or production.
15
+ test:
16
+ adapter: sqlite3
17
+ database: db/test.sqlite3
18
+ pool: 5
19
+ timeout: 5000
20
+
21
+ production:
22
+ adapter: sqlite3
23
+ database: db/production.sqlite3
24
+ pool: 5
25
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the Rails application.
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the Rails application.
5
+ Dummy::Application.initialize!
@@ -0,0 +1,29 @@
1
+ Dummy::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the web server when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
+
12
+ # Show full error reports and disable caching.
13
+ config.consider_all_requests_local = true
14
+ config.action_controller.perform_caching = false
15
+
16
+ # Don't care if the mailer can't send.
17
+ config.action_mailer.raise_delivery_errors = false
18
+
19
+ # Print deprecation notices to the Rails logger.
20
+ config.active_support.deprecation = :log
21
+
22
+ # Raise an error on page load if there are pending migrations
23
+ config.active_record.migration_error = :page_load
24
+
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
29
+ end