Commit 44cc52bc85929c7821a0e9a74331e33b6e30ccde
Exists in
staging
and in
27 other branches
Merge branch 'organization_ratings_config' into 'master'
organization_ratings: add intial_page option Creates an option in organization_ratings plugin to config how many ratings will appear on the initial page of every ratings block. After clicking on "view more" option, the "per_page" option will be used normally to paginate all the ratings. Also, this merge request fixes a commented test for pagination config validation. See merge request !940
Showing
6 changed files
with
43 additions
and
9 deletions
Show diff stats
plugins/organization_ratings/db/migrate/20160523193515_add_initial_page_to_organization_ratings_config.rb
0 → 100644
... | ... | @@ -0,0 +1,9 @@ |
1 | +class AddInitialPageToOrganizationRatingsConfig < ActiveRecord::Migration | |
2 | + def up | |
3 | + add_column :organization_ratings_configs, :ratings_on_initial_page, :integer, :default => 3 | |
4 | + end | |
5 | + | |
6 | + def down | |
7 | + remove_column :organization_ratings_configs, :ratings_on_initial_page | |
8 | + end | |
9 | +end | ... | ... |
plugins/organization_ratings/lib/organization_ratings_block.rb
plugins/organization_ratings/lib/organization_ratings_config.rb
... | ... | @@ -4,6 +4,7 @@ class OrganizationRatingsConfig < ApplicationRecord |
4 | 4 | |
5 | 5 | attr_accessible :cooldown, :default_rating, :order, :per_page |
6 | 6 | attr_accessible :vote_once, :are_moderated, :environment_id |
7 | + attr_accessible :ratings_on_initial_page | |
7 | 8 | |
8 | 9 | ORDER_OPTIONS = {recent: _('More Recent'), best: _('Best Ratings')} |
9 | 10 | ... | ... |
plugins/organization_ratings/test/unit/organization_rating_config_test.rb
... | ... | @@ -29,15 +29,29 @@ class OrganizationRatingConfigTest < ActiveSupport::TestCase |
29 | 29 | assert_equal "must be greater than or equal to 0", @organization_ratings_config.errors[:cooldown].first |
30 | 30 | end |
31 | 31 | |
32 | - # test "communities ratings per page validation" do | |
33 | - # environment = Environment.new :communities_ratings_per_page => 4 | |
34 | - # environment.valid? | |
32 | + test "communities ratings per page validation" do | |
33 | + @organization_ratings_config.per_page = 4 | |
35 | 34 | |
36 | - # assert_equal "must be greater than or equal to 5", environment.errors[:communities_ratings_per_page].first | |
35 | + refute @organization_ratings_config.valid? | |
37 | 36 | |
38 | - # environment.communities_ratings_per_page = 21 | |
39 | - # environment.valid? | |
37 | + assert_equal "must be greater than or equal to 5", @organization_ratings_config.errors[:per_page].first | |
40 | 38 | |
41 | - # assert_equal "must be less than or equal to 20", environment.errors[:communities_ratings_per_page].first | |
42 | - # end | |
39 | + @organization_ratings_config.per_page = 21 | |
40 | + refute @organization_ratings_config.valid? | |
41 | + | |
42 | + assert_equal "must be less than or equal to 20", @organization_ratings_config.errors[:per_page].first | |
43 | + end | |
44 | + | |
45 | + should "ratings block use initial_page config" do | |
46 | + @organization_ratings_config.ratings_on_initial_page = 4 | |
47 | + @organization_ratings_config.save! | |
48 | + block = OrganizationRatingsBlock.new | |
49 | + assert_equal block.ratings_on_initial_page, 4 | |
50 | + end | |
51 | + | |
52 | + should "ratings block show 3 ratings on initial page by default" do | |
53 | + @organization_ratings_config.save! | |
54 | + block = OrganizationRatingsBlock.new | |
55 | + assert_equal block.ratings_on_initial_page, 3 | |
56 | + end | |
43 | 57 | end | ... | ... |
plugins/organization_ratings/views/blocks/organization_ratings.html.erb
... | ... | @@ -7,7 +7,7 @@ |
7 | 7 | <% else %> |
8 | 8 | <div class="ratings-list"> |
9 | 9 | <% block.get_ratings(block.owner.id).each_with_index do |r, index| %> |
10 | - <% break if index >= block.limit_number_of_ratings %> | |
10 | + <% break if index >= block.ratings_on_initial_page %> | |
11 | 11 | <%= render :partial => "shared/user_rating_container", :locals => {:user_rate => r} %> |
12 | 12 | <% end %> |
13 | 13 | ... | ... |
plugins/organization_ratings/views/organization_ratings_plugin_admin/index.html.erb
... | ... | @@ -43,6 +43,12 @@ |
43 | 43 | <%= c.select :per_page, 5..20 %> |
44 | 44 | </td> |
45 | 45 | </tr> |
46 | + <tr> | |
47 | + <td><%= _('Ratings amount on initial page') %></td> | |
48 | + <td> | |
49 | + <%= c.select :ratings_on_initial_page, 1..10 %> | |
50 | + </td> | |
51 | + </tr> | |
46 | 52 | </table> |
47 | 53 | <div> |
48 | 54 | <%= button_bar do %> | ... | ... |