diff --git a/app/controllers/my_profile/themes_controller.rb b/app/controllers/my_profile/themes_controller.rb
index 06ff502..457c111 100644
--- a/app/controllers/my_profile/themes_controller.rb
+++ b/app/controllers/my_profile/themes_controller.rb
@@ -8,6 +8,11 @@ class ThemesController < MyProfileController
redirect_to :action => 'index'
end
+ def unset
+ profile.update_theme(nil)
+ redirect_to :action => 'index'
+ end
+
def index
@themes = profile.environment.themes + Theme.approved_themes(profile)
@current_theme = profile.theme
diff --git a/app/models/environment.rb b/app/models/environment.rb
index fb8de02..e62789a 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -564,7 +564,15 @@ class Environment < ActiveRecord::Base
end
def themes=(values)
- settings[:themes] = values.map(&:id)
+ settings[:themes] = values
+ end
+
+ def add_themes(values)
+ if settings[:themes].nil?
+ self.themes = values
+ else
+ settings[:themes] += values
+ end
end
def community_template
diff --git a/app/views/themes/index.rhtml b/app/views/themes/index.rhtml
index 671bc88..0354489 100644
--- a/app/views/themes/index.rhtml
+++ b/app/views/themes/index.rhtml
@@ -37,6 +37,7 @@
<%= _('Select theme') %>
+ <%= button :home, _('Use the default theme'), { :action => 'unset'}, :method => 'post', :confirm => _('Are you sure you want to use the environment default theme?') %>
|
<% for themes in @themes.in_groups_of(3) %>
diff --git a/lib/delayed_attachment_fu.rb b/lib/delayed_attachment_fu.rb
index 87ffbf8..312bf92 100644
--- a/lib/delayed_attachment_fu.rb
+++ b/lib/delayed_attachment_fu.rb
@@ -38,7 +38,7 @@ module DelayedAttachmentFu
end
def public_filename(size=nil)
- if self.thumbnails_processed
+ if !self.thumbnailable? || self.thumbnails_processed
super(size)
else
size ||= 'thumb'
diff --git a/test/functional/themes_controller_test.rb b/test/functional/themes_controller_test.rb
index 1d62456..eda3386 100644
--- a/test/functional/themes_controller_test.rb
+++ b/test/functional/themes_controller_test.rb
@@ -31,12 +31,12 @@ class ThemesControllerTest < Test::Unit::TestCase
should 'display themes that can be applied' do
env = Environment.default
Theme.stubs(:approved_themes).with(@profile).returns([Theme.new('t1', :name => 't1')])
- t2 = Theme.create('t2')
- t3 = Theme.create('t3')
+ t2 = 't2'
+ t3 = 't3'
env.themes = [t2]
env.save
- Theme.stubs(:system_themes).returns([t2, t3])
+ Theme.stubs(:system_themes).returns([Theme.new(t2), Theme.new(t3)])
get :index, :profile => 'testinguser'
%w[ t1 t2 ].each do |item|
@@ -48,13 +48,13 @@ class ThemesControllerTest < Test::Unit::TestCase
should 'highlight current theme' do
env = Environment.default
- t1 = Theme.create('one', :name => 'one')
- t2 = Theme.create('two', :name => 'two')
+ t1 = 'one'
+ t2 = 'two'
env.themes = [t1, t2]
env.save
- Theme.stubs(:system_themes).returns([t1, t2])
- profile.update_attributes(:theme => 'one')
+ Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2)])
+ profile.update_theme(t1)
get :index, :profile => 'testinguser'
assert_tag :attributes => { :class => 'selected theme' }, :descendant => { :content => /(current)/ }
@@ -88,6 +88,22 @@ class ThemesControllerTest < Test::Unit::TestCase
assert_equal 'onetheme', profile.theme
end
+ should 'unset selection of theme' do
+ get :unset, :profile => 'testinguser'
+ assert_equal nil, profile.theme
+ end
+
+ should 'display link to use the default theme' do
+ env = Environment.default
+ env.themes = ['new-theme']
+ env.save
+
+ Theme.stubs(:system_themes).returns([Theme.new('new-theme')])
+
+ get :index, :profile => 'testinguser'
+ assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/unset" }
+ end
+
should 'point back to control panel' do
get :index, :profile => 'testinguser'
assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back'
diff --git a/test/unit/application_helper_test.rb b/test/unit/application_helper_test.rb
index 23cd158..cdbc1c3 100644
--- a/test/unit/application_helper_test.rb
+++ b/test/unit/application_helper_test.rb
@@ -532,9 +532,10 @@ class ApplicationHelperTest < Test::Unit::TestCase
should 'use favicon from profile articles if the profile theme does not have' do
stubs(:environment).returns(fast_create(Environment, :theme => 'new-theme'))
stubs(:profile).returns(fast_create(Profile, :theme => 'profile-theme'))
- file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/favicon.ico', 'image/png'), :profile => profile)
+ file = UploadedFile.create!(:uploaded_data => fixture_file_upload('/files/favicon.ico', 'image/x-ico'), :profile => profile)
File.expects(:exists?).with(File.join(RAILS_ROOT, 'public', theme_path, 'favicon.ico')).returns(false)
- assert_equal file.public_filename, theme_favicon
+
+ assert_match /favicon.ico/, theme_favicon
end
should 'use favicon from environment if the profile theme and profile articles do not have' do
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index f118347..9560797 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -465,27 +465,40 @@ class EnvironmentTest < Test::Unit::TestCase
should 'have a list of themes' do
env = Environment.default
- t1 = mock
- t2 = mock
- t1.stubs(:id).returns('theme_1')
- t2.stubs(:id).returns('theme_2')
+ t1 = 'theme_1'
+ t2 = 'theme_2'
- Theme.expects(:system_themes).returns([t1, t2])
+ Theme.expects(:system_themes).returns([Theme.new(t1), Theme.new(t2)])
env.themes = [t1, t2]
env.save!
- assert_equal [t1, t2], Environment.default.themes
+ assert_equal [t1, t2], Environment.default.themes.map(&:id)
end
should 'set themes to environment' do
env = Environment.default
- t1 = mock
- t1.stubs(:id).returns('theme_1')
+ env.themes = ['new-theme']
+ env.save
+ assert_equal ['new-theme'], Environment.default.settings[:themes]
+ end
+
+ should 'return only themes included on system_themes' do
+ Theme.expects(:system_themes).returns([Theme.new('new-theme')])
+ env = Environment.default
+
+ env.themes = ['new-theme', 'other-theme']
+ env.save
+ assert_equal ['new-theme'], Environment.default.themes.map(&:id)
+ end
+
+ should 'add new themes to environment' do
+ Theme.expects(:system_themes).returns([Theme.new('new-theme'), Theme.new('other-theme')])
+ env = Environment.default
- env.themes = [t1]
+ env.add_themes(['new-theme', 'other-theme'])
env.save
- assert_equal [t1.id], Environment.default.settings[:themes]
+ assert_equal ['new-theme', 'other-theme'], Environment.default.themes.map(&:id)
end
should 'create templates' do
diff --git a/test/unit/image_test.rb b/test/unit/image_test.rb
index 8357b30..6fbcdb2 100644
--- a/test/unit/image_test.rb
+++ b/test/unit/image_test.rb
@@ -57,6 +57,7 @@ class ImageTest < Test::Unit::TestCase
should 'have a default image if thumbnails were not processed' do
file = Image.new
+ file.expects(:thumbnailable?).returns(true)
assert_equal '/images/icons-app/image-loading-thumb.png', file.public_filename(:thumb)
end
diff --git a/test/unit/uploaded_file_test.rb b/test/unit/uploaded_file_test.rb
index 91cd2d0..8fb0d34 100644
--- a/test/unit/uploaded_file_test.rb
+++ b/test/unit/uploaded_file_test.rb
@@ -196,6 +196,7 @@ class UploadedFileTest < Test::Unit::TestCase
should 'have a default image if thumbnails were not processed' do
file = UploadedFile.new
+ file.expects(:thumbnailable?).returns(true)
assert_equal '/images/icons-app/image-loading-thumb.png', file.public_filename
end
--
libgit2 0.21.2