Commit 08509c62cf78c76525d353f02f6d9ea7901aed83
Committed by
Antonio Terceiro
1 parent
a52001ff
Exists in
master
and in
23 other branches
Fixed problems with profile's theme
* Enhancing the way a theme is set to an environment * Allowing users to remove the theme of a profile * Fixed delayed_attachment_fu, so favicon (not thumbnailable file) won't display loading image (ActionItem1675)
Showing
9 changed files
with
67 additions
and
21 deletions
Show diff stats
app/controllers/my_profile/themes_controller.rb
| @@ -8,6 +8,11 @@ class ThemesController < MyProfileController | @@ -8,6 +8,11 @@ class ThemesController < MyProfileController | ||
| 8 | redirect_to :action => 'index' | 8 | redirect_to :action => 'index' |
| 9 | end | 9 | end |
| 10 | 10 | ||
| 11 | + def unset | ||
| 12 | + profile.update_theme(nil) | ||
| 13 | + redirect_to :action => 'index' | ||
| 14 | + end | ||
| 15 | + | ||
| 11 | def index | 16 | def index |
| 12 | @themes = profile.environment.themes + Theme.approved_themes(profile) | 17 | @themes = profile.environment.themes + Theme.approved_themes(profile) |
| 13 | @current_theme = profile.theme | 18 | @current_theme = profile.theme |
app/models/environment.rb
| @@ -564,7 +564,15 @@ class Environment < ActiveRecord::Base | @@ -564,7 +564,15 @@ class Environment < ActiveRecord::Base | ||
| 564 | end | 564 | end |
| 565 | 565 | ||
| 566 | def themes=(values) | 566 | def themes=(values) |
| 567 | - settings[:themes] = values.map(&:id) | 567 | + settings[:themes] = values |
| 568 | + end | ||
| 569 | + | ||
| 570 | + def add_themes(values) | ||
| 571 | + if settings[:themes].nil? | ||
| 572 | + self.themes = values | ||
| 573 | + else | ||
| 574 | + settings[:themes] += values | ||
| 575 | + end | ||
| 568 | end | 576 | end |
| 569 | 577 | ||
| 570 | def community_template | 578 | def community_template |
app/views/themes/index.rhtml
| @@ -37,6 +37,7 @@ | @@ -37,6 +37,7 @@ | ||
| 37 | <tr> | 37 | <tr> |
| 38 | <td colspan='6'> | 38 | <td colspan='6'> |
| 39 | <h2><%= _('Select theme') %></h2> | 39 | <h2><%= _('Select theme') %></h2> |
| 40 | + <%= button :home, _('Use the default theme'), { :action => 'unset'}, :method => 'post', :confirm => _('Are you sure you want to use the environment default theme?') %> | ||
| 40 | </td> | 41 | </td> |
| 41 | </tr> | 42 | </tr> |
| 42 | <% for themes in @themes.in_groups_of(3) %> | 43 | <% for themes in @themes.in_groups_of(3) %> |
lib/delayed_attachment_fu.rb
| @@ -38,7 +38,7 @@ module DelayedAttachmentFu | @@ -38,7 +38,7 @@ module DelayedAttachmentFu | ||
| 38 | end | 38 | end |
| 39 | 39 | ||
| 40 | def public_filename(size=nil) | 40 | def public_filename(size=nil) |
| 41 | - if self.thumbnails_processed | 41 | + if !self.thumbnailable? || self.thumbnails_processed |
| 42 | super(size) | 42 | super(size) |
| 43 | else | 43 | else |
| 44 | size ||= 'thumb' | 44 | size ||= 'thumb' |
test/functional/themes_controller_test.rb
| @@ -31,12 +31,12 @@ class ThemesControllerTest < Test::Unit::TestCase | @@ -31,12 +31,12 @@ class ThemesControllerTest < Test::Unit::TestCase | ||
| 31 | should 'display themes that can be applied' do | 31 | should 'display themes that can be applied' do |
| 32 | env = Environment.default | 32 | env = Environment.default |
| 33 | Theme.stubs(:approved_themes).with(@profile).returns([Theme.new('t1', :name => 't1')]) | 33 | Theme.stubs(:approved_themes).with(@profile).returns([Theme.new('t1', :name => 't1')]) |
| 34 | - t2 = Theme.create('t2') | ||
| 35 | - t3 = Theme.create('t3') | 34 | + t2 = 't2' |
| 35 | + t3 = 't3' | ||
| 36 | env.themes = [t2] | 36 | env.themes = [t2] |
| 37 | env.save | 37 | env.save |
| 38 | 38 | ||
| 39 | - Theme.stubs(:system_themes).returns([t2, t3]) | 39 | + Theme.stubs(:system_themes).returns([Theme.new(t2), Theme.new(t3)]) |
| 40 | get :index, :profile => 'testinguser' | 40 | get :index, :profile => 'testinguser' |
| 41 | 41 | ||
| 42 | %w[ t1 t2 ].each do |item| | 42 | %w[ t1 t2 ].each do |item| |
| @@ -48,13 +48,13 @@ class ThemesControllerTest < Test::Unit::TestCase | @@ -48,13 +48,13 @@ class ThemesControllerTest < Test::Unit::TestCase | ||
| 48 | 48 | ||
| 49 | should 'highlight current theme' do | 49 | should 'highlight current theme' do |
| 50 | env = Environment.default | 50 | env = Environment.default |
| 51 | - t1 = Theme.create('one', :name => 'one') | ||
| 52 | - t2 = Theme.create('two', :name => 'two') | 51 | + t1 = 'one' |
| 52 | + t2 = 'two' | ||
| 53 | env.themes = [t1, t2] | 53 | env.themes = [t1, t2] |
| 54 | env.save | 54 | env.save |
| 55 | 55 | ||
| 56 | - Theme.stubs(:system_themes).returns([t1, t2]) | ||
| 57 | - profile.update_attributes(:theme => 'one') | 56 | + Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2)]) |
| 57 | + profile.update_theme(t1) | ||
| 58 | get :index, :profile => 'testinguser' | 58 | get :index, :profile => 'testinguser' |
| 59 | 59 | ||
| 60 | assert_tag :attributes => { :class => 'selected theme' }, :descendant => { :content => /(current)/ } | 60 | assert_tag :attributes => { :class => 'selected theme' }, :descendant => { :content => /(current)/ } |
| @@ -88,6 +88,22 @@ class ThemesControllerTest < Test::Unit::TestCase | @@ -88,6 +88,22 @@ class ThemesControllerTest < Test::Unit::TestCase | ||
| 88 | assert_equal 'onetheme', profile.theme | 88 | assert_equal 'onetheme', profile.theme |
| 89 | end | 89 | end |
| 90 | 90 | ||
| 91 | + should 'unset selection of theme' do | ||
| 92 | + get :unset, :profile => 'testinguser' | ||
| 93 | + assert_equal nil, profile.theme | ||
| 94 | + end | ||
| 95 | + | ||
| 96 | + should 'display link to use the default theme' do | ||
| 97 | + env = Environment.default | ||
| 98 | + env.themes = ['new-theme'] | ||
| 99 | + env.save | ||
| 100 | + | ||
| 101 | + Theme.stubs(:system_themes).returns([Theme.new('new-theme')]) | ||
| 102 | + | ||
| 103 | + get :index, :profile => 'testinguser' | ||
| 104 | + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/unset" } | ||
| 105 | + end | ||
| 106 | + | ||
| 91 | should 'point back to control panel' do | 107 | should 'point back to control panel' do |
| 92 | get :index, :profile => 'testinguser' | 108 | get :index, :profile => 'testinguser' |
| 93 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back' | 109 | assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back' |
test/unit/application_helper_test.rb
| @@ -532,9 +532,10 @@ class ApplicationHelperTest < Test::Unit::TestCase | @@ -532,9 +532,10 @@ class ApplicationHelperTest < Test::Unit::TestCase | ||
| 532 | should 'use favicon from profile articles if the profile theme does not have' do | 532 | should 'use favicon from profile articles if the profile theme does not have' do |
| 533 | stubs(:environment).returns(fast_create(Environment, :theme => 'new-theme')) | 533 | stubs(:environment).returns(fast_create(Environment, :theme => 'new-theme')) |
| 534 | stubs(:profile).returns(fast_create(Profile, :theme => 'profile-theme')) | 534 | stubs(:profile).returns(fast_create(Profile, :theme => 'profile-theme')) |
| 535 | - file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/favicon.ico', 'image/png'), :profile => profile) | 535 | + file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/favicon.ico', 'image/x-ico'), :profile => profile) |
| 536 | File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', theme_path, 'favicon.ico')).returns(false) | 536 | File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', theme_path, 'favicon.ico')).returns(false) |
| 537 | - assert_equal file.public_filename, theme_favicon | 537 | + |
| 538 | + assert_match /favicon.ico/, theme_favicon | ||
| 538 | end | 539 | end |
| 539 | 540 | ||
| 540 | should 'use favicon from environment if the profile theme and profile articles do not have' do | 541 | should 'use favicon from environment if the profile theme and profile articles do not have' do |
test/unit/environment_test.rb
| @@ -465,27 +465,40 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -465,27 +465,40 @@ class EnvironmentTest < Test::Unit::TestCase | ||
| 465 | 465 | ||
| 466 | should 'have a list of themes' do | 466 | should 'have a list of themes' do |
| 467 | env = Environment.default | 467 | env = Environment.default |
| 468 | - t1 = mock | ||
| 469 | - t2 = mock | ||
| 470 | 468 | ||
| 471 | - t1.stubs(:id).returns('theme_1') | ||
| 472 | - t2.stubs(:id).returns('theme_2') | 469 | + t1 = 'theme_1' |
| 470 | + t2 = 'theme_2' | ||
| 473 | 471 | ||
| 474 | - Theme.expects(:system_themes).returns([t1, t2]) | 472 | + Theme.expects(:system_themes).returns([Theme.new(t1), Theme.new(t2)]) |
| 475 | env.themes = [t1, t2] | 473 | env.themes = [t1, t2] |
| 476 | env.save! | 474 | env.save! |
| 477 | - assert_equal [t1, t2], Environment.default.themes | 475 | + assert_equal [t1, t2], Environment.default.themes.map(&:id) |
| 478 | end | 476 | end |
| 479 | 477 | ||
| 480 | should 'set themes to environment' do | 478 | should 'set themes to environment' do |
| 481 | env = Environment.default | 479 | env = Environment.default |
| 482 | - t1 = mock | ||
| 483 | 480 | ||
| 484 | - t1.stubs(:id).returns('theme_1') | 481 | + env.themes = ['new-theme'] |
| 482 | + env.save | ||
| 483 | + assert_equal ['new-theme'], Environment.default.settings[:themes] | ||
| 484 | + end | ||
| 485 | + | ||
| 486 | + should 'return only themes included on system_themes' do | ||
| 487 | + Theme.expects(:system_themes).returns([Theme.new('new-theme')]) | ||
| 488 | + env = Environment.default | ||
| 489 | + | ||
| 490 | + env.themes = ['new-theme', 'other-theme'] | ||
| 491 | + env.save | ||
| 492 | + assert_equal ['new-theme'], Environment.default.themes.map(&:id) | ||
| 493 | + end | ||
| 494 | + | ||
| 495 | + should 'add new themes to environment' do | ||
| 496 | + Theme.expects(:system_themes).returns([Theme.new('new-theme'), Theme.new('other-theme')]) | ||
| 497 | + env = Environment.default | ||
| 485 | 498 | ||
| 486 | - env.themes = [t1] | 499 | + env.add_themes(['new-theme', 'other-theme']) |
| 487 | env.save | 500 | env.save |
| 488 | - assert_equal [t1.id], Environment.default.settings[:themes] | 501 | + assert_equal ['new-theme', 'other-theme'], Environment.default.themes.map(&:id) |
| 489 | end | 502 | end |
| 490 | 503 | ||
| 491 | should 'create templates' do | 504 | should 'create templates' do |
test/unit/image_test.rb
| @@ -57,6 +57,7 @@ class ImageTest < Test::Unit::TestCase | @@ -57,6 +57,7 @@ class ImageTest < Test::Unit::TestCase | ||
| 57 | 57 | ||
| 58 | should 'have a default image if thumbnails were not processed' do | 58 | should 'have a default image if thumbnails were not processed' do |
| 59 | file = Image.new | 59 | file = Image.new |
| 60 | + file.expects(:thumbnailable?).returns(true) | ||
| 60 | assert_equal '/images/icons-app/image-loading-thumb.png', file.public_filename(:thumb) | 61 | assert_equal '/images/icons-app/image-loading-thumb.png', file.public_filename(:thumb) |
| 61 | end | 62 | end |
| 62 | 63 |
test/unit/uploaded_file_test.rb
| @@ -196,6 +196,7 @@ class UploadedFileTest < Test::Unit::TestCase | @@ -196,6 +196,7 @@ class UploadedFileTest < Test::Unit::TestCase | ||
| 196 | 196 | ||
| 197 | should 'have a default image if thumbnails were not processed' do | 197 | should 'have a default image if thumbnails were not processed' do |
| 198 | file = UploadedFile.new | 198 | file = UploadedFile.new |
| 199 | + file.expects(:thumbnailable?).returns(true) | ||
| 199 | assert_equal '/images/icons-app/image-loading-thumb.png', file.public_filename | 200 | assert_equal '/images/icons-app/image-loading-thumb.png', file.public_filename |
| 200 | end | 201 | end |
| 201 | 202 |