diff --git a/app/controllers/my_profile/themes_controller.rb b/app/controllers/my_profile/themes_controller.rb index 52ee04e..83d3f92 100644 --- a/app/controllers/my_profile/themes_controller.rb +++ b/app/controllers/my_profile/themes_controller.rb @@ -1,3 +1,15 @@ -class ThemesController < ApplicationController +class ThemesController < MyProfileController + no_design_blocks + + def set + profile.update_attributes!(:theme => params[:id]) + redirect_to :action => 'index' + end + + def index + @themes = Theme.system_themes + @selected_theme = profile.theme + end + end diff --git a/app/models/theme.rb b/app/models/theme.rb new file mode 100644 index 0000000..57503cf --- /dev/null +++ b/app/models/theme.rb @@ -0,0 +1,22 @@ +class Theme + + attr_reader :id + + def initialize(id) + @id = id + end + + def name + id + end + + class << self + def system_themes + Dir.glob(RAILS_ROOT + '/public/designs/themes/*').map do |item| + File.basename(item) + end.map do |item| + new(item) + end + end + end +end diff --git a/app/views/themes/index.rhtml b/app/views/themes/index.rhtml new file mode 100644 index 0000000..a2028e4 --- /dev/null +++ b/app/views/themes/index.rhtml @@ -0,0 +1,14 @@ +

<%= _('Editing Appearance') %>

+ +

<%= _('Select theme') %>

+ +
+ <% for theme in @themes %> + <%= 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 %> + <% end %> +
+ + +<% button_bar do %> + <%= button(:back, _('Back'), :controller => 'profile_editor', :action => 'index') %> +<% end %> diff --git a/test/functional/themes_controller_test.rb b/test/functional/themes_controller_test.rb index 164b716..573f5b5 100644 --- a/test/functional/themes_controller_test.rb +++ b/test/functional/themes_controller_test.rb @@ -1,8 +1,43 @@ require File.dirname(__FILE__) + '/../test_helper' class ThemesControllerTest < ActionController::TestCase - # Replace this with your real tests. - def test_truth - assert true + + should 'display list of themes for selection' do + profile = create_user('testinguser').person + Theme.expects(:system_themes).returns([Theme.new('first'), Theme.new('second')]) + get :index, :profile => 'testinguser' + + %w[ first second ].each do |item| + assert_tag :tag => 'a', :attributes => { :href => "/myprofile/testinguser/themes/set/#{item}" }, :descendant => { :tag => 'img' } + end + end + + should 'save selection of theme' do + profile = create_user('testinguser').person + + get :set, :profile => 'testinguser', :id => 'onetheme' + profile.reload + assert_equal 'onetheme', profile.theme + end + + should 'point back to control panel' do + create_user('testinguser').person + get :index, :profile => 'testinguser' + assert_tag :tag => 'a', :attributes => { :href => '/myprofile/testinguser' }, :content => 'Back' end + + should 'check access control when choosing theme' + + should 'check access control when editing themes' + + should 'only allow environment-approved themes to be selected' + + should 'list user-created themes with link for editing' + + should 'offer to create new theme' + + should 'be able to save new theme' + + should 'be able to save existing theme' + end diff --git a/test/unit/theme_test.rb b/test/unit/theme_test.rb new file mode 100644 index 0000000..86af0a9 --- /dev/null +++ b/test/unit/theme_test.rb @@ -0,0 +1,20 @@ +require File.dirname(__FILE__) + '/../test_helper' + +class ThemeTest < ActiveSupport::TestCase + should 'list system themes' do + Dir.expects(:glob).with(RAILS_ROOT + '/public/designs/themes/*').returns( + [ + RAILS_ROOT + '/public/designs/themes/themeone', + RAILS_ROOT + '/public/designs/themes/themetwo', + RAILS_ROOT + '/public/designs/themes/themethree' + ]) + + assert_equal ['themeone', 'themetwo', 'themethree'], Theme.system_themes.map(&:id) + end + + should 'use id as name by default' do + assert_equal 'the-id', Theme.new('the-id').name + end + +end + -- libgit2 0.21.2