railsthemes 1.2.0 → 2.0.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +15 -0
  2. data/.rvmrc +2 -4
  3. data/Gemfile +4 -6
  4. data/Rakefile +8 -5
  5. data/bin/railsthemes +20 -24
  6. data/features/railsthemes.feature +11 -0
  7. data/features/support/env.rb +1 -0
  8. data/lib/railsthemes/email_installer.rb +16 -77
  9. data/lib/railsthemes/ensurer.rb +3 -3
  10. data/lib/railsthemes/installer.rb +118 -142
  11. data/lib/railsthemes/switcher.rb +33 -0
  12. data/lib/railsthemes/tar.rb +4 -5
  13. data/lib/railsthemes/theme_installer.rb +144 -102
  14. data/lib/railsthemes/utils.rb +148 -107
  15. data/lib/railsthemes/version.rb +1 -1
  16. data/lib/railsthemes.rb +2 -9
  17. data/spec/fixtures/blank-assets/{email/app/assets/stylesheets/email.css → tier1-erb-scss/controllers/controller1.rb} +0 -0
  18. data/spec/fixtures/blank-assets/{erb-css/base/app/assets/images/bg/sprite.png → tier1-erb-scss/helpers/helper1.rb} +0 -0
  19. data/spec/fixtures/blank-assets/{erb-css/base/app/assets/images/image1.png → tier1-erb-scss/images/image1.jpg} +0 -0
  20. data/spec/fixtures/blank-assets/{erb-css/base/app/assets/javascripts/jquery.dataTables.js → tier1-erb-scss/javascripts/file1.js} +0 -0
  21. data/spec/fixtures/blank-assets/{erb-css/base/app/assets/javascripts/scripts.js.erb → tier1-erb-scss/layouts/layout1.html.haml} +0 -0
  22. data/spec/fixtures/blank-assets/{erb-css/base/app/views/layouts/_interior_sidebar.html.erb → tier1-erb-scss/mailers/mailer.rb} +0 -0
  23. data/spec/fixtures/blank-assets/{erb-css/base/app/views/layouts/application.html.erb → tier1-erb-scss/stylesheets/stylesheet1.css.scss} +0 -0
  24. data/spec/fixtures/blank-assets-archived/tier1-erb-scss.tar.gz +0 -0
  25. data/spec/lib/railsthemes/email_installer_spec.rb +10 -20
  26. data/spec/lib/railsthemes/ensurer_spec.rb +9 -9
  27. data/spec/lib/railsthemes/installer_spec.rb +90 -75
  28. data/spec/lib/railsthemes/switcher_spec.rb +82 -0
  29. data/spec/lib/railsthemes/theme_installer_spec.rb +323 -109
  30. data/spec/lib/railsthemes/utils_spec.rb +43 -3
  31. data/spec/spec_helper.rb +49 -0
  32. metadata +95 -122
  33. data/lib/railsthemes/asset_installer.rb +0 -48
  34. data/spec/fixtures/blank-assets/erb-css/base/app/assets/stylesheets/style.css.erb +0 -1
  35. data/spec/fixtures/blank-assets/erb-css/base/app/views/layouts/homepage.html.erb +0 -0
  36. data/spec/fixtures/blank-assets/erb-css/gems/formtastic/app/assets/stylesheets/formtastic.css.scss +0 -0
  37. data/spec/fixtures/blank-assets/erb-css/gems/simple_form/app/assets/stylesheets/simple_form.css.scss +0 -0
  38. data/spec/fixtures/blank-assets-archived/design-assets.tar.gz +0 -0
  39. data/spec/fixtures/blank-assets-archived/email.tar.gz +0 -0
  40. data/spec/fixtures/blank-assets-archived/erb-css.tar.gz +0 -0
  41. data/spec/lib/railsthemes/asset_installer_spec.rb +0 -10
@@ -9,38 +9,28 @@ describe Railsthemes::EmailInstaller do
9
9
  end
10
10
 
11
11
  describe '#install_mail_gems_if_necessary' do
12
- it 'should install no new gems if premailer-rails3 gem already installed' do
13
- File.open('Gemfile.lock', 'w') do |f|
14
- f.write using_gems 'premailer-rails3', 'hpricot'
15
- end
12
+ it 'should install no new gems if premailer-rails gem already installed' do
13
+ write_gemfiles_using_gems 'premailer-rails', 'hpricot'
16
14
  dont_allow(Railsthemes::Utils).add_gem_to_gemfile(anything)
17
- dont_allow(Railsthemes::Safe).system_call('bundle')
18
15
  @installer.install_mail_gems_if_necessary
19
16
  end
20
17
 
21
- it 'when nokogiri already installed, should install the pr3 gem' do
22
- File.open('Gemfile.lock', 'w') do |f|
23
- f.write using_gems 'nokogiri'
24
- end
25
- mock(Railsthemes::Utils).add_gem_to_gemfile('premailer-rails3')
26
- mock(Railsthemes::Safe).system_call('bundle')
18
+ it 'when nokogiri already installed, should install the pr gem' do
19
+ write_gemfiles_using_gems 'nokogiri'
20
+ mock(Railsthemes::Utils).add_gem_to_gemfile('premailer-rails')
27
21
  @installer.install_mail_gems_if_necessary
28
22
  end
29
23
 
30
- it 'when hpricot already installed, should install the pr3 gem only' do
31
- File.open('Gemfile.lock', 'w') do |f|
32
- f.write using_gems 'hpricot'
33
- end
34
- mock(Railsthemes::Utils).add_gem_to_gemfile('premailer-rails3')
35
- mock(Railsthemes::Safe).system_call('bundle')
24
+ it 'when hpricot already installed, should install the pr gem only' do
25
+ write_gemfiles_using_gems 'hpricot'
26
+ mock(Railsthemes::Utils).add_gem_to_gemfile('premailer-rails')
36
27
  @installer.install_mail_gems_if_necessary
37
28
  end
38
29
 
39
- it 'when no xml gem or pr3 installed, should install the pr3 gem and hpricot' do
30
+ it 'when no xml gem or pr installed, should install the pr gem and hpricot' do
40
31
  FileUtils.touch('Gemfile.lock')
41
32
  mock(Railsthemes::Utils).add_gem_to_gemfile('hpricot')
42
- mock(Railsthemes::Utils).add_gem_to_gemfile('premailer-rails3')
43
- mock(Railsthemes::Safe).system_call('bundle')
33
+ mock(Railsthemes::Utils).add_gem_to_gemfile('premailer-rails')
44
34
  @installer.install_mail_gems_if_necessary
45
35
  end
46
36
  end
@@ -13,8 +13,8 @@ describe Railsthemes::Ensurer do
13
13
  mock(Railsthemes::Ensurer).ensure_railsthemes_is_not_in_gemfile.times(1)
14
14
  mock(Railsthemes::Ensurer).ensure_vcs_is_clean.times(1)
15
15
  mock(Railsthemes::Ensurer).ensure_rails_version_is_valid.times(1)
16
- mock(Railsthemes::Ensurer).ensure_installer_is_up_to_date.times(1)
17
- 2.times { Railsthemes::Ensurer.ensure_clean_install_possible }
16
+ mock(Railsthemes::Ensurer).ensure_installer_is_up_to_date('server').times(1)
17
+ 2.times { Railsthemes::Ensurer.ensure_clean_install_possible :server => 'server' }
18
18
  end
19
19
 
20
20
  it 'should do twice if force passed' do
@@ -23,8 +23,8 @@ describe Railsthemes::Ensurer do
23
23
  mock(Railsthemes::Ensurer).ensure_railsthemes_is_not_in_gemfile.times(2)
24
24
  mock(Railsthemes::Ensurer).ensure_vcs_is_clean.times(2)
25
25
  mock(Railsthemes::Ensurer).ensure_rails_version_is_valid.times(2)
26
- mock(Railsthemes::Ensurer).ensure_installer_is_up_to_date.times(2)
27
- 2.times { Railsthemes::Ensurer.ensure_clean_install_possible :force => true }
26
+ mock(Railsthemes::Ensurer).ensure_installer_is_up_to_date('server').times(2)
27
+ 2.times { Railsthemes::Ensurer.ensure_clean_install_possible :server => 'server', :force => true }
28
28
  end
29
29
 
30
30
  it 'should not check installer version if we do not want to hit the server' do
@@ -34,7 +34,7 @@ describe Railsthemes::Ensurer do
34
34
  mock(Railsthemes::Ensurer).ensure_vcs_is_clean
35
35
  mock(Railsthemes::Ensurer).ensure_rails_version_is_valid
36
36
  dont_allow(Railsthemes::Ensurer).ensure_installer_is_up_to_date
37
- Railsthemes::Ensurer.ensure_clean_install_possible :hit_server => false, :force => true
37
+ Railsthemes::Ensurer.ensure_clean_install_possible :server => false, :force => true
38
38
  end
39
39
  end
40
40
 
@@ -61,7 +61,7 @@ describe Railsthemes::Ensurer do
61
61
  message.should match(/Recommended version: 1\.0\.4/)
62
62
  end
63
63
  with_installer_version '1.0.3' do
64
- Railsthemes::Ensurer.ensure_installer_is_up_to_date
64
+ Railsthemes::Ensurer.ensure_installer_is_up_to_date('http://example.com')
65
65
  end
66
66
  end
67
67
 
@@ -69,7 +69,7 @@ describe Railsthemes::Ensurer do
69
69
  FakeWeb.register_uri :get, /\/installer\/version$/, :body => '1.0.4'
70
70
  dont_allow(Railsthemes::Safe).log_and_abort(anything)
71
71
  with_installer_version '1.0.4' do
72
- Railsthemes::Ensurer.ensure_installer_is_up_to_date
72
+ Railsthemes::Ensurer.ensure_installer_is_up_to_date('http://example.com')
73
73
  end
74
74
  end
75
75
 
@@ -77,7 +77,7 @@ describe Railsthemes::Ensurer do
77
77
  FakeWeb.register_uri :get, /\/installer\/version$/, :body => '1.0.4'
78
78
  dont_allow(Railsthemes::Safe).log_and_abort(anything)
79
79
  with_installer_version '1.0.5' do
80
- Railsthemes::Ensurer.ensure_installer_is_up_to_date
80
+ Railsthemes::Ensurer.ensure_installer_is_up_to_date('http://example.com')
81
81
  end
82
82
  end
83
83
 
@@ -85,7 +85,7 @@ describe Railsthemes::Ensurer do
85
85
  FakeWeb.register_uri :get, /\/installer\/version$/,
86
86
  :body => '', :status => ['401', 'Unauthorized']
87
87
  mock(Railsthemes::Safe).log_and_abort(/issue checking your installer version/)
88
- Railsthemes::Ensurer.ensure_installer_is_up_to_date
88
+ Railsthemes::Ensurer.ensure_installer_is_up_to_date('http://example.com')
89
89
  end
90
90
  end
91
91
 
@@ -9,62 +9,77 @@ describe Railsthemes::Installer do
9
9
  @tempdir = stub_tempdir
10
10
 
11
11
  stub(Railsthemes::Ensurer).ensure_clean_install_possible
12
+ stub(Railsthemes::Safe).system_call('bundle')
12
13
  end
13
14
 
14
- describe :install_from_file_system do
15
- before do
16
- FakeFS::FileSystem.clone('spec/fixtures')
17
- stub(Railsthemes::Utils).get_primary_configuration { ['erb', 'css'] }
15
+ describe 'initialization' do
16
+ describe 'server' do
17
+ it 'should default to production' do
18
+ installer = Railsthemes::Installer.new
19
+ installer.server.should == 'https://railsthemes.com'
20
+ end
21
+
22
+ it 'should be right when in staging' do
23
+ installer = Railsthemes::Installer.new(:staging => true)
24
+ installer.server.should == 'http://staging.railsthemes.com'
25
+ end
26
+
27
+ it 'should be right when server passed in' do
28
+ installer = Railsthemes::Installer.new(:server => 'http://example.com')
29
+ installer.server.should == 'http://example.com'
30
+ end
18
31
  end
19
32
 
20
- describe 'installing theme' do
21
- before do
22
- stub(@installer.email_installer).install_from_file_system(anything)
23
- stub(@installer.asset_installer).install_from_file_system(anything)
33
+ describe 'documentation popup' do
34
+ it 'should pop up when it is not mentioned' do
35
+ installer = Railsthemes::Installer.new
36
+ installer.doc_popup.should be_true
24
37
  end
25
38
 
26
- it 'should install the right theme version' do
27
- mock(@installer.theme_installer).install_from_file_system('spec/fixtures/blank-assets/erb-css')
28
- @installer.install_from_file_system 'spec/fixtures/blank-assets'
39
+ it 'should not pop up when configured to not pop up' do
40
+ installer = Railsthemes::Installer.new(:no_doc_popup => true)
41
+ installer.doc_popup.should be_false
29
42
  end
30
43
 
31
- it 'should install the right theme version if it is an archive in that directory' do
32
- mock(@installer.theme_installer).install_from_file_system('spec/fixtures/blank-assets-archived/erb-css')
33
- @installer.install_from_file_system 'spec/fixtures/blank-assets-archived'
44
+ it 'should pop up when configured to pop up' do
45
+ installer = Railsthemes::Installer.new(:no_doc_popup => false)
46
+ installer.doc_popup.should be_true
34
47
  end
35
48
  end
49
+ end
36
50
 
37
- describe 'installing email theme' do
38
- before do
39
- stub(@installer.theme_installer).install_from_file_system(anything)
40
- stub(@installer.asset_installer).install_from_file_system(anything)
41
- end
51
+ describe :install_from_file_system do
52
+ before do
53
+ FakeFS::FileSystem.clone('spec/fixtures')
54
+ @theme_installer = @installer.theme_installer
55
+ end
42
56
 
43
- it 'should install the email theme if present' do
44
- mock(@installer.email_installer).install_from_file_system('spec/fixtures/blank-assets/email')
45
- @installer.install_from_file_system 'spec/fixtures/blank-assets'
57
+ describe 'installing theme' do
58
+ it 'should install the right theme version' do
59
+ mock(@theme_installer).install_from_file_system('spec/fixtures/blank-assets/tier1-erb-scss')
60
+ @installer.install_from_file_system 'spec/fixtures/blank-assets/tier1-erb-scss'
46
61
  end
47
62
 
48
- it 'should install the archived email theme if present' do
49
- mock(@installer.email_installer).install_from_file_system('spec/fixtures/blank-assets-archived/email')
50
- @installer.install_from_file_system 'spec/fixtures/blank-assets-archived'
63
+ it 'should install the right theme version if it is an archive in that directory' do
64
+ mock(@theme_installer).install_from_file_system('spec/fixtures/blank-assets-archived/tier1-erb-scss')
65
+ @installer.install_from_file_system 'spec/fixtures/blank-assets-archived/tier1-erb-scss'
51
66
  end
52
67
  end
53
68
 
54
- describe 'installing design assets theme' do
69
+ describe 'installing email' do
55
70
  before do
56
- stub(@installer.theme_installer).install_from_file_system(anything)
57
- stub(@installer.email_installer).install_from_file_system(anything)
71
+ create_file 'theme/views/test.txt'
58
72
  end
59
73
 
60
- it 'should install the design assets if present' do
61
- mock(@installer.asset_installer).install_from_file_system('spec/fixtures/blank-assets/design-assets')
62
- @installer.install_from_file_system 'spec/fixtures/blank-assets'
74
+ it 'should install email if it is present' do
75
+ create_file 'theme/mailers/railsthemes_mailer/test.txt'
76
+ mock(@installer.email_installer).install
77
+ @installer.install_from_file_system('theme')
63
78
  end
64
79
 
65
- it 'should install the archived design assets if present' do
66
- mock(@installer.asset_installer).install_from_file_system('spec/fixtures/blank-assets-archived/design-assets')
67
- @installer.install_from_file_system 'spec/fixtures/blank-assets-archived'
80
+ it 'should not install email if it is not present' do
81
+ dont_allow(@installer.email_installer).install
82
+ @installer.install_from_file_system('theme')
68
83
  end
69
84
  end
70
85
  end
@@ -75,51 +90,55 @@ describe Railsthemes::Installer do
75
90
  before do
76
91
  FakeFS::FileSystem.clone('spec/fixtures')
77
92
  stub(@installer.theme_installer).install_from_file_system(anything)
78
- stub(@installer.email_installer).install_from_file_system(anything)
79
93
  end
80
94
 
81
95
  it 'should not pop it up when the user specified not to pop it up' do
82
96
  @installer.doc_popup = false
83
97
  dont_allow(@installer).popup_documentation
84
- @installer.install_from_file_system 'spec/fixtures/blank-assets'
98
+ @installer.install_from_file_system 'spec/fixtures/blank-assets/tier1-erb-scss'
85
99
  end
86
100
 
87
101
  it 'should pop it up when the user did not specify to not pop it up' do
88
102
  mock(@installer).popup_documentation
89
- @installer.install_from_file_system 'spec/fixtures/blank-assets'
103
+ @installer.install_from_file_system 'spec/fixtures/blank-assets/tier1-erb-scss'
90
104
  end
91
105
  end
92
106
  end
93
107
 
94
- describe 'popup_documentation' do
108
+ describe '#popup_documentation' do
95
109
  it 'should not open if the style guide does not exist' do
96
110
  dont_allow(Launchy).open(anything)
97
111
  @installer.popup_documentation
98
112
  end
99
113
 
100
- it 'should open the style guide correctly if it exists' do
101
- FileUtils.mkdir_p('doc')
102
- filename = 'doc/Theme_Envy_Usage_And_Style_Guide.html'
103
- FileUtils.touch(filename)
114
+ it 'should open guides correctly if they exist' do
115
+ filename = 'doc/railsthemes_themename/test.html'
116
+ create_file(filename)
104
117
  mock(Launchy).open(filename)
105
118
  @installer.popup_documentation
106
119
  end
107
- end
108
120
 
109
- describe '#download_from_hash' do
110
- it 'should download and install main theme when theme specified' do
111
- mock(Railsthemes::Utils).download(:url => 'theme_url', :save_to => "dir/erb-css.tar.gz")
112
- @installer.download_from_hash({'theme' => 'theme_url'}, 'dir')
121
+ it 'should open docs from the latest folder' do
122
+ create_file(old = 'doc/railsthemes_oldtheme/test.html')
123
+ create_file(new = 'doc/railsthemes_newtheme/test.html')
124
+ dont_allow(Launchy).open(old)
125
+ mock(Launchy).open(new)
126
+ @installer.popup_documentation
113
127
  end
114
128
 
115
- it 'should download and install email theme when email specified' do
116
- mock(Railsthemes::Utils).download(:url => 'email_url', :save_to => "dir/email.tar.gz")
117
- @installer.download_from_hash({'email' => 'email_url'}, 'dir')
129
+ it 'should open multiple docs' do
130
+ create_file(new1 = 'doc/railsthemes_newtheme/test1.html')
131
+ create_file(new2 = 'doc/railsthemes_newtheme/test2.html')
132
+ mock(Launchy).open(new1)
133
+ mock(Launchy).open(new2)
134
+ @installer.popup_documentation
118
135
  end
136
+ end
119
137
 
120
- it 'should download and install design assets when that is specified' do
121
- mock(Railsthemes::Utils).download(:url => 'asset_url', :save_to => "dir/design-assets.tar.gz")
122
- @installer.download_from_hash({'design_assets' => 'asset_url'}, 'dir')
138
+ describe '#download_from_url' do
139
+ it 'should download theme' do
140
+ mock(Railsthemes::Utils).download(:url => 'theme url', :save_to => "dir/rt-archive.tar.gz")
141
+ @installer.download_from_url('theme url', 'dir')
123
142
  end
124
143
  end
125
144
 
@@ -129,38 +148,38 @@ describe Railsthemes::Installer do
129
148
  end
130
149
 
131
150
  it 'should download and install when the code is recognized' do
132
- mock(@installer).get_download_hash('code') { :hash }
133
- mock(@installer).download_from_hash(:hash, @tempdir)
134
- mock(@installer).install_from_file_system(@tempdir)
151
+ mock(@installer).get_download_url('code') { 'url' }
152
+ mock(@installer).download_from_url('url', @tempdir)
153
+ mock(@installer).install_from_file_system("#{@tempdir}/rt-archive")
135
154
  @installer.install_from_code 'code'
136
155
  end
137
156
 
138
157
  it 'should print an error message when the code is not recognized' do
139
- mock(@installer).get_download_hash('code') { nil }
140
- dont_allow(@installer).download_from_hash(:hash, @tempdir)
141
- dont_allow(@installer).install_from_file_system(@tempdir)
158
+ mock(@installer).get_download_url('code') { nil }
159
+ dont_allow(@installer).download_from_url(anything, anything)
160
+ dont_allow(@installer).install_from_file_system(anything)
142
161
  mock(Railsthemes::Safe).log_and_abort(/didn't recognize/)
143
162
  @installer.install_from_code 'code'
144
163
  end
145
164
  end
146
165
 
147
- describe '#get_download_hash' do
148
- it 'should download the file correctly when valid configuration' do
166
+ describe '#get_download_url' do
167
+ it 'should return the url when valid configuration' do
168
+ stub(Railsthemes::Utils).get_primary_configuration { ['haml', 'scss'] }
149
169
  FakeWeb.register_uri :get,
150
170
  /download\?code=panozzaj@gmail.com:code&config=haml,scss&v=2/,
151
- :body => { 'theme' => 'auth_url' }.to_json
152
- mock(Railsthemes::Utils).get_primary_configuration { ['haml', 'scss'] }
153
- result = @installer.get_download_hash 'panozzaj@gmail.com:code'
154
- result.should == { 'theme' => 'auth_url' }
171
+ :body => 'auth_url'
172
+ result = @installer.get_download_url 'panozzaj@gmail.com:code'
173
+ result.should == 'auth_url'
155
174
  end
156
175
 
157
- it 'should fail with an error message on any error message' do
176
+ it 'should return nil when cannot download' do
177
+ stub(Railsthemes::Utils).get_primary_configuration { [] }
158
178
  FakeWeb.register_uri :get,
159
179
  'https://railsthemes.com/download?code=panozzaj@gmail.com:code&config=',
160
180
  :body => '', :status => ['401', 'Unauthorized']
161
- mock(Railsthemes::Utils).get_primary_configuration { [] }
162
- mock(Railsthemes::Safe).log_and_abort(/didn't recognize/)
163
- @installer.install_from_code 'panozzaj@gmail.com:code'
181
+ result = @installer.get_download_url 'panozzaj@gmail.com:code'
182
+ result.should == nil
164
183
  end
165
184
  end
166
185
 
@@ -174,13 +193,11 @@ describe Railsthemes::Installer do
174
193
 
175
194
  context 'with Gemfile.lock present' do
176
195
  before do
177
- File.open('Gemfile.lock', 'w') do |file|
178
- file.puts "GEM\n remote: https://rubygems.org/"
179
- end
196
+ FakeFS.deactivate! # has an issue with generating tmpfiles otherwise
197
+ # this gives us a Gemfile.lock since we have it on the actual filesystem
180
198
  end
181
199
 
182
200
  it 'should hit the server with the Gemfile and return the results, arrayified' do
183
- FakeFS.deactivate! # has an issue with generating tmpfiles otherwise
184
201
  params = { :code => 'panozzaj@gmail.com:code', :gemfile_lock => File.new('Gemfile.lock', 'rb') }
185
202
  FakeWeb.register_uri :post, 'https://railsthemes.com/gemfiles/parse',
186
203
  :body => 'haml,scss', :parameters => params
@@ -188,12 +205,10 @@ describe Railsthemes::Installer do
188
205
  end
189
206
 
190
207
  it 'should return a blank array when there are issues' do
191
- FakeFS.deactivate! # has an issue with generating tmpfiles otherwise
192
208
  FakeWeb.register_uri :post, 'https://railsthemes.com/gemfiles/parse',
193
209
  :body => '', :parameters => :any, :status => ['401', 'Unauthorized']
194
210
  @installer.send_gemfile('panozzaj@gmail.com:code')
195
211
  end
196
212
  end
197
213
  end
198
-
199
214
  end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+ require 'railsthemes'
3
+
4
+ describe Railsthemes::Switcher do
5
+ before do
6
+ setup_logger
7
+ @switcher = Railsthemes::Switcher.new
8
+ @tempdir = stub_tempdir
9
+ end
10
+
11
+ describe '#list' do
12
+ context 'no themes are available' do
13
+ it 'should output no themes available' do
14
+ mock(@switcher).installed_themes { [] }
15
+ mock(Railsthemes::Logging.logger).warn 'There are currently no RailsThemes themes installed.'
16
+ @switcher.list
17
+ end
18
+ end
19
+
20
+ context 'themes are available' do
21
+ it 'should output the themes' do
22
+ mock(@switcher).installed_themes { ['theme1', 'theme2'] }
23
+ mock(Railsthemes::Logging.logger).warn 'RailsThemes themes currently installed:'
24
+ mock(Railsthemes::Logging.logger).warn ' - theme1'
25
+ mock(Railsthemes::Logging.logger).warn ' - theme2'
26
+ @switcher.list
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#switch_to' do
32
+ context 'when there are themes installed' do
33
+ before do
34
+ mock(@switcher).installed_themes { ['foo', 'bar'] }
35
+ end
36
+
37
+ it 'should use the theme when it is an installed theme' do
38
+ mock(Railsthemes::Utils).set_layout_in_application_controller('bar')
39
+ @switcher.switch_to 'bar'
40
+ end
41
+
42
+ it 'should not use the theme when it is not installed' do
43
+ dont_allow(Railsthemes::Utils).set_layout_in_application_controller(anything)
44
+ mock(Railsthemes::Logging.logger).warn "'quux' is not a locally installed RailsThemes theme."
45
+ @switcher.switch_to 'quux'
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#installed_themes' do
51
+ context 'there are no themes installed' do
52
+ it 'should show nothing installed ' do
53
+ @switcher.installed_themes.should == []
54
+ end
55
+ end
56
+
57
+ context 'one theme installed' do
58
+ before do
59
+ create_file('app/assets/stylesheets/railsthemes_theme1.css')
60
+ create_file('app/assets/stylesheets/railsthemes_theme1/something.css')
61
+ end
62
+
63
+ it 'should show the theme installed' do
64
+ @switcher.installed_themes.should == ['theme1']
65
+ end
66
+ end
67
+
68
+ context 'many themes installed' do
69
+ before do
70
+ create_file('app/assets/stylesheets/railsthemes_theme1.css')
71
+ create_file('app/assets/stylesheets/railsthemes_theme1/something.css')
72
+ create_file('app/assets/stylesheets/railsthemes_theme2.css')
73
+ create_file('app/assets/stylesheets/railsthemes_theme2/something.css')
74
+ end
75
+
76
+ it 'should show the installed themes' do
77
+ @switcher.installed_themes.should == ['theme1', 'theme2']
78
+ end
79
+ end
80
+ end
81
+
82
+ end