Commit 89e0c33d3e031a1ed237ba07818c54bbb5ab8230
1 parent
229119fe
Exists in
master
and in
29 other branches
ActionItem122: starting to implement controller
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2391 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
107 additions
and
4 deletions
Show diff stats
app/controllers/my_profile/themes_controller.rb
| 1 | -class ThemesController < ApplicationController | 1 | +class ThemesController < MyProfileController |
| 2 | + | ||
| 2 | no_design_blocks | 3 | no_design_blocks |
| 4 | + | ||
| 5 | + def set | ||
| 6 | + profile.update_attributes!(:theme => params[:id]) | ||
| 7 | + redirect_to :action => 'index' | ||
| 8 | + end | ||
| 9 | + | ||
| 10 | + def index | ||
| 11 | + @themes = Theme.system_themes | ||
| 12 | + @selected_theme = profile.theme | ||
| 13 | + end | ||
| 14 | + | ||
| 3 | end | 15 | end |
| @@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
| 1 | +class Theme | ||
| 2 | + | ||
| 3 | + attr_reader :id | ||
| 4 | + | ||
| 5 | + def initialize(id) | ||
| 6 | + @id = id | ||
| 7 | + end | ||
| 8 | + | ||
| 9 | + def name | ||
| 10 | + id | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + class << self | ||
| 14 | + def system_themes | ||
| 15 | + Dir.glob(RAILS_ROOT + '/public/designs/themes/*').map do |item| | ||
| 16 | + File.basename(item) | ||
| 17 | + end.map do |item| | ||
| 18 | + new(item) | ||
| 19 | + end | ||
| 20 | + end | ||
| 21 | + end | ||
| 22 | +end |
| @@ -0,0 +1,14 @@ | @@ -0,0 +1,14 @@ | ||
| 1 | +<h1><%= _('Editing Appearance') %></h1> | ||
| 2 | + | ||
| 3 | +<h2><%= _('Select theme') %></h2> | ||
| 4 | + | ||
| 5 | +<div> | ||
| 6 | + <% for theme in @themes %> | ||
| 7 | + <%= link_to image_tag('/images/icons-app/design-editor.png', :alt => (_('Select the "%s" theme.') % theme.name)) + content_tag('span', theme.name), :action => 'set', :id => theme.id %> | ||
| 8 | + <% end %> | ||
| 9 | +</div> | ||
| 10 | + | ||
| 11 | + | ||
| 12 | +<% button_bar do %> | ||
| 13 | + <%= button(:back, _('Back'), :controller => 'profile_editor', :action => 'index') %> | ||
| 14 | +<% end %> |
test/functional/themes_controller_test.rb
| 1 | require File.dirname(__FILE__) + '/../test_helper' | 1 | require File.dirname(__FILE__) + '/../test_helper' |
| 2 | 2 | ||
| 3 | class ThemesControllerTest < ActionController::TestCase | 3 | class ThemesControllerTest < ActionController::TestCase |
| 4 | - # Replace this with your real tests. | ||
| 5 | - def test_truth | ||
| 6 | - assert true | 4 | + |
| 5 | + should 'display list of themes for selection' do | ||
| 6 | + profile = create_user('testinguser').person | ||
| 7 | + Theme.expects(:system_themes).returns([Theme.new('first'), Theme.new('second')]) | ||
| 8 | + get :index, :profile => 'testinguser' | ||
| 9 | + | ||
| 10 | + %w[ first second ].each do |item| | ||
| 11 | + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/#{item}" }, :descendant => { :tag => 'img' } | ||
| 12 | + end | ||
| 13 | + end | ||
| 14 | + | ||
| 15 | + should 'save selection of theme' do | ||
| 16 | + profile = create_user('testinguser').person | ||
| 17 | + | ||
| 18 | + get :set, :profile => 'testinguser', :id => 'onetheme' | ||
| 19 | + profile.reload | ||
| 20 | + assert_equal 'onetheme', profile.theme | ||
| 21 | + end | ||
| 22 | + | ||
| 23 | + should 'point back to control panel' do | ||
| 24 | + create_user('testinguser').person | ||
| 25 | + get :index, :profile => 'testinguser' | ||
| 26 | + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back' | ||
| 7 | end | 27 | end |
| 28 | + | ||
| 29 | + should 'check access control when choosing theme' | ||
| 30 | + | ||
| 31 | + should 'check access control when editing themes' | ||
| 32 | + | ||
| 33 | + should 'only allow environment-approved themes to be selected' | ||
| 34 | + | ||
| 35 | + should 'list user-created themes with link for editing' | ||
| 36 | + | ||
| 37 | + should 'offer to create new theme' | ||
| 38 | + | ||
| 39 | + should 'be able to save new theme' | ||
| 40 | + | ||
| 41 | + should 'be able to save existing theme' | ||
| 42 | + | ||
| 8 | end | 43 | end |
| @@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
| 1 | +require File.dirname(__FILE__) + '/../test_helper' | ||
| 2 | + | ||
| 3 | +class ThemeTest < ActiveSupport::TestCase | ||
| 4 | + should 'list system themes' do | ||
| 5 | + Dir.expects(:glob).with(RAILS_ROOT + '/public/designs/themes/*').returns( | ||
| 6 | + [ | ||
| 7 | + RAILS_ROOT + '/public/designs/themes/themeone', | ||
| 8 | + RAILS_ROOT + '/public/designs/themes/themetwo', | ||
| 9 | + RAILS_ROOT + '/public/designs/themes/themethree' | ||
| 10 | + ]) | ||
| 11 | + | ||
| 12 | + assert_equal ['themeone', 'themetwo', 'themethree'], Theme.system_themes.map(&:id) | ||
| 13 | + end | ||
| 14 | + | ||
| 15 | + should 'use id as name by default' do | ||
| 16 | + assert_equal 'the-id', Theme.new('the-id').name | ||
| 17 | + end | ||
| 18 | + | ||
| 19 | +end | ||
| 20 | + |