Commit 229119feb3a231d1b7bd9d2da2bbed6f09d264c0
1 parent
6f1ddaea
Exists in
master
and in
29 other branches
ActionItem122: implementing storage of theme info
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2390 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
72 additions
and
8 deletions
Show diff stats
app/helpers/application_helper.rb
... | ... | @@ -153,7 +153,7 @@ module ApplicationHelper |
153 | 153 | # should be a current profile (i.e. while viewing some profile's pages, or the |
154 | 154 | # profile info, etc), because if there is no profile an exception is thrown. |
155 | 155 | def profile |
156 | - @controller.send(:profile) || raise("There is no current profile") | |
156 | + @controller.send(:profile) | |
157 | 157 | end |
158 | 158 | |
159 | 159 | def category_color |
... | ... | @@ -328,9 +328,13 @@ module ApplicationHelper |
328 | 328 | result << '/stylesheets/' << name << '.css' |
329 | 329 | end |
330 | 330 | |
331 | - # FIXME do not hardcode 'default' like this | |
332 | 331 | def current_theme |
333 | - 'default' | |
332 | + p = profile | |
333 | + if p | |
334 | + p.theme | |
335 | + else | |
336 | + @environment.theme | |
337 | + end | |
334 | 338 | end |
335 | 339 | |
336 | 340 | # generates a image tag for the profile. | ... | ... |
app/models/environment.rb
app/models/profile.rb
... | ... | @@ -0,0 +1,15 @@ |
1 | +class AddThemeAttribute < ActiveRecord::Migration | |
2 | + TABLE = [ :profiles, :environments ] | |
3 | + | |
4 | + def self.up | |
5 | + TABLE.each do |table| | |
6 | + add_column table, :theme, :string | |
7 | + end | |
8 | + end | |
9 | + | |
10 | + def self.down | |
11 | + TABLE.each do |table| | |
12 | + remove_column table, :theme | |
13 | + end | |
14 | + end | |
15 | +end | ... | ... |
db/schema.rb
... | ... | @@ -9,7 +9,7 @@ |
9 | 9 | # |
10 | 10 | # It's strongly recommended to check this file into your version control system. |
11 | 11 | |
12 | -ActiveRecord::Schema.define(:version => 48) do | |
12 | +ActiveRecord::Schema.define(:version => 49) do | |
13 | 13 | |
14 | 14 | create_table "article_versions", :force => true do |t| |
15 | 15 | t.integer "article_id" |
... | ... | @@ -145,6 +145,7 @@ ActiveRecord::Schema.define(:version => 48) do |
145 | 145 | t.text "design_data" |
146 | 146 | t.text "custom_header" |
147 | 147 | t.text "custom_footer" |
148 | + t.string "theme" | |
148 | 149 | end |
149 | 150 | |
150 | 151 | create_table "favorite_enteprises_people", :id => false, :force => true do |t| |
... | ... | @@ -217,6 +218,7 @@ ActiveRecord::Schema.define(:version => 48) do |
217 | 218 | t.string "nickname", :limit => 16 |
218 | 219 | t.text "custom_header" |
219 | 220 | t.text "custom_footer" |
221 | + t.string "theme" | |
220 | 222 | end |
221 | 223 | |
222 | 224 | add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" | ... | ... |
test/unit/application_helper_test.rb
... | ... | @@ -64,11 +64,8 @@ class ApplicationHelperTest < Test::Unit::TestCase |
64 | 64 | assert_same result, link_to_category(cat) |
65 | 65 | end |
66 | 66 | |
67 | - should 'get current theme' do | |
68 | - assert_equal 'default', current_theme() | |
69 | - end | |
70 | - | |
71 | 67 | should 'nil theme option when no exists theme' do |
68 | + stubs(:current_theme).returns('something-very-unlikely') | |
72 | 69 | File.expects(:exists?).returns(false) |
73 | 70 | assert_nil theme_option() |
74 | 71 | end |
... | ... | @@ -84,6 +81,7 @@ class ApplicationHelperTest < Test::Unit::TestCase |
84 | 81 | end |
85 | 82 | |
86 | 83 | should 'nil javascript theme when no exists theme' do |
84 | + stubs(:current_theme).returns('something-very-unlikely') | |
87 | 85 | File.expects(:exists?).returns(false) |
88 | 86 | assert_nil theme_javascript |
89 | 87 | end |
... | ... | @@ -138,6 +136,21 @@ class ApplicationHelperTest < Test::Unit::TestCase |
138 | 136 | #assert_no_match /parent category/, result |
139 | 137 | end |
140 | 138 | |
139 | + should 'get theme from environment by default' do | |
140 | + @environment = mock | |
141 | + @environment.stubs(:theme).returns('my-environment-theme') | |
142 | + stubs(:profile).returns(nil) | |
143 | + assert_equal 'my-environment-theme', current_theme | |
144 | + end | |
145 | + | |
146 | + should 'get theme from profile when profile is present' do | |
147 | + profile = mock | |
148 | + profile.stubs(:theme).returns('my-profile-theme') | |
149 | + stubs(:profile).returns(profile) | |
150 | + assert_equal 'my-profile-theme', current_theme | |
151 | + end | |
152 | + | |
153 | + | |
141 | 154 | protected |
142 | 155 | |
143 | 156 | def content_tag(tag, content, options = {}) | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -355,4 +355,12 @@ class EnvironmentTest < Test::Unit::TestCase |
355 | 355 | assert_equal 'my footer', Environment.new(:custom_footer => "my footer").custom_footer |
356 | 356 | end |
357 | 357 | |
358 | + should 'provide theme' do | |
359 | + assert_equal 'my-custom-theme', Environment.new(:theme => 'my-custom-theme').theme | |
360 | + end | |
361 | + | |
362 | + should 'give default theme' do | |
363 | + assert_equal 'default', Environment.new.theme | |
364 | + end | |
365 | + | |
358 | 366 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -771,6 +771,20 @@ class ProfileTest < Test::Unit::TestCase |
771 | 771 | assert_equal 'environment footer', profile.custom_footer |
772 | 772 | end |
773 | 773 | |
774 | + should 'store theme' do | |
775 | + p = Profile.new(:theme => 'my-shiny-theme') | |
776 | + assert_equal 'my-shiny-theme', p.theme | |
777 | + end | |
778 | + | |
779 | + should 'delegate theme selection to environment by default' do | |
780 | + p = Profile.new | |
781 | + env = mock | |
782 | + p.stubs(:environment).returns(env) | |
783 | + env.expects(:theme).returns('environment-stored-theme') | |
784 | + | |
785 | + assert_equal 'environment-stored-theme', p.theme | |
786 | + end | |
787 | + | |
774 | 788 | private |
775 | 789 | |
776 | 790 | def assert_invalid_identifier(id) | ... | ... |