Commit cfb2b54198c2f4048663bffcd0c809b2f1df4af1
Committed by
Daniela Feitosa
1 parent
8c5ac225
Exists in
master
and in
29 other branches
ProfileListBlock option to prioritize profiles with image
(ActionItem1800)
Showing
3 changed files
with
27 additions
and
3 deletions
Show diff stats
app/models/profile_list_block.rb
1 | 1 | class ProfileListBlock < Block |
2 | 2 | |
3 | 3 | settings_items :limit, :type => :integer, :default => 6 |
4 | + settings_items :prioritize_profiles_with_image, :type => :boolean, :default => false | |
4 | 5 | |
5 | 6 | def self.description |
6 | 7 | _('Random profiles') |
... | ... | @@ -12,8 +13,7 @@ class ProfileListBlock < Block |
12 | 13 | end |
13 | 14 | |
14 | 15 | def profile_list |
15 | - random = randomizer | |
16 | - profiles.visible.all(:limit => limit, :select => 'DISTINCT profiles.*, ' + random, :order => random) | |
16 | + profiles.visible.all(:include => :image, :limit => limit, :select => 'DISTINCT profiles.*, ' + image_prioritizer + randomizer, :order => image_prioritizer + randomizer) | |
17 | 17 | end |
18 | 18 | |
19 | 19 | def profile_count |
... | ... | @@ -24,6 +24,10 @@ class ProfileListBlock < Block |
24 | 24 | @randomizer ||= "(profiles.id % #{rand(profile_count) + 1})" |
25 | 25 | end |
26 | 26 | |
27 | + def image_prioritizer | |
28 | + prioritize_profiles_with_image ? '(images.id is null),' : '' | |
29 | + end | |
30 | + | |
27 | 31 | # the title of the block. Probably will be overriden in subclasses. |
28 | 32 | def default_title |
29 | 33 | _('{#} People or Groups') | ... | ... |
app/views/box_organizer/_profile_list_block.rhtml
test/unit/profile_list_block_test.rb
... | ... | @@ -145,7 +145,7 @@ class ProfileListBlockTest < Test::Unit::TestCase |
145 | 145 | block.stubs(:owner).returns(env) |
146 | 146 | |
147 | 147 | # force the "random" function to return something we know |
148 | - block.stubs(:randomizer).returns('-id') | |
148 | + block.stubs(:randomizer).returns('-profiles.id') | |
149 | 149 | |
150 | 150 | assert_equal [p3.id, p2.id, p1.id], block.profile_list.map(&:id) |
151 | 151 | end |
... | ... | @@ -164,4 +164,23 @@ class ProfileListBlockTest < Test::Unit::TestCase |
164 | 164 | assert_no_match /profiles.id % 0/, block.randomizer |
165 | 165 | end |
166 | 166 | |
167 | + should 'prioritize profiles with image if this option is turned on' do | |
168 | + env = fast_create(Environment) | |
169 | + p1 = fast_create(Person, :environment_id => env.id) | |
170 | + img1 = Image.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :owner => p1) | |
171 | + p2 = fast_create(Person, :environment_id => env.id) | |
172 | + img2 = Image.create!(:uploaded_data => fixture_file_upload('/files/rails.png', 'image/png'), :owner => p2) | |
173 | + | |
174 | + p_without_image = fast_create(Person, :environment_id => env.id) | |
175 | + | |
176 | + block = ProfileListBlock.new | |
177 | + block.stubs(:owner).returns(env) | |
178 | + block.stubs(:prioritize_profiles_with_image).returns(true) | |
179 | + | |
180 | + # force the "random" function to return something we know | |
181 | + block.stubs(:randomizer).returns('-profiles.id') | |
182 | + | |
183 | + assert_not_includes block.profile_list[0..1], p_without_image | |
184 | + end | |
185 | + | |
167 | 186 | end | ... | ... |