ref: master
test/functional/environment_themes_controller_test.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
require_relative "../test_helper" class EnvironmentThemesControllerTest < ActionController::TestCase def setup @controller = EnvironmentThemesController.new Theme.stubs(:user_themes_dir).returns(TMP_THEMES_DIR) @env = Environment.default login = create_admin_user(@env) login_as(login) @profile = User.find_by(login: login).person end def teardown FileUtils.rm_rf(TMP_THEMES_DIR) end TMP_THEMES_DIR = Rails.root.join("test", "tmp", "environment_themes_controller") should 'display themes that can be applied' do env = Environment.default Theme.stubs(:approved_themes).with(@env).returns([]) t1 = 't1' t2 = 't2' t3 = 't3' env.themes = [t1, t2] env.save Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2), Theme.new(t3)]) get :index %w[ t1 t2 ].each do |item| assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set/#{item}" } end assert_no_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set/t3" } end should 'highlight current theme' do env = Environment.default t1 = 'one' t2 = 'two' env.themes = [t1, t2] env.save Theme.stubs(:system_themes).returns([Theme.new(t1), Theme.new(t2)]) env.update_theme(t1) get :index assert_tag :attributes => { :class => 'theme-opt list-opt selected' } assert_no_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set/one" } end should 'save selection of theme' do get :set, :id => 'onetheme' env = Environment.default assert_equal 'onetheme', env.theme end should 'unset selection of theme' do get :unset env = Environment.default assert_equal 'default', env.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 assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/unset" } end should 'point back to admin panel' do get :index assert_tag :tag => 'a', :attributes => { :href => '/admin' }, :content => 'Back' end should 'list templates' do all = LayoutTemplate.all LayoutTemplate.expects(:all).returns(all) get :index assert_equivalent all, assigns(:layout_templates) end should 'display links to set template' do env = Environment.default env.layout_template = 'rightbar' env.save! t1 = LayoutTemplate.find('default') t2 = LayoutTemplate.find('leftbar') LayoutTemplate.expects(:all).returns([t1, t2]) get :index assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set_layout_template/default"} assert_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set_layout_template/leftbar"} end should 'highlight current template' do env = Environment.default env.update_attribute(:layout_template, 'default') env.layout_template = 'default' t1 = LayoutTemplate.find('default') t2 = LayoutTemplate.find('leftbar') LayoutTemplate.expects(:all).returns([t1, t2]) get :index assert_tag :attributes => { :class => 'template-opt list-opt selected' } assert_no_tag :tag => 'a', :attributes => { :href => "/admin/environment_themes/set_layout_template/default"} end should 'set template' do env = Environment.default post :set_layout_template, :id => 'leftbar' env.reload assert_equal 'leftbar', env.layout_template assert_redirected_to :action => 'index' end should 'not display the "Select themes" section if there are no themes to choose from' do env = Environment.default env.themes = []; env.save! Theme.stubs(:system_themes_dir).returns(TMP_THEMES_DIR) # an empty dir get :index assert_no_tag :content => "Select theme" end end |