contao 0.3.1

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.
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ module TechnoGate
4
+ describe Contao do
5
+ describe "#env" do
6
+ it {should respond_to :env}
7
+ it {should respond_to :env=}
8
+
9
+ it "should return @@env" do
10
+ mock("env").tap do |env|
11
+ subject.class_variable_set(:@@env, env)
12
+ subject.env.should == env
13
+ end
14
+ end
15
+
16
+ it "should set the @@env" do
17
+ mock("env").tap do |env|
18
+ subject.env = env
19
+ subject.class_variable_get(:@@env).should == env
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '#root' do
25
+ it {should respond_to :root}
26
+ it {should respond_to :root=}
27
+
28
+ it "should return @@root" do
29
+ mock("root").tap do |root|
30
+ subject.class_variable_set(:@@root, root)
31
+ subject.root.should == root
32
+ end
33
+ end
34
+
35
+ it "should set the @@root" do
36
+ mock("root").tap do |root|
37
+ subject.root = root
38
+ subject.class_variable_get(:@@root).should == Pathname.new(root).expand_path
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '#expandify' do
44
+ before :each do
45
+ subject.root = '/root'
46
+ end
47
+
48
+ it {should respond_to :expandify}
49
+
50
+ it "should expand the path if it's relative" do
51
+ subject.expandify('app').to_s.should == '/root/app'
52
+ end
53
+
54
+ it "should not expand an expanded path" do
55
+ subject.expandify('/test').to_s.should == '/test'
56
+ end
57
+
58
+ it "always return a Pathname" do
59
+ subject.expandify('app').should be_instance_of Pathname
60
+ subject.expandify('/app').should be_instance_of Pathname
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,245 @@
1
+ require 'spec_helper'
2
+
3
+ module Guard
4
+ describe Assets do
5
+ it "should inherit from Guard" do
6
+ subject.class.superclass.should == ::Guard::Guard
7
+ end
8
+
9
+ describe '#init' do
10
+ it "should create @coffeescript_compiler" do
11
+ subject.instance_variable_get(:@coffeescript_compiler).
12
+ should be_instance_of TechnoGate::Contao::CoffeescriptCompiler
13
+ end
14
+
15
+ it "should create @javascript_compiler" do
16
+ subject.instance_variable_get(:@javascript_compiler).
17
+ should be_instance_of TechnoGate::Contao::JavascriptCompiler
18
+ end
19
+
20
+ it "should create @stylesheet_compiler" do
21
+ subject.instance_variable_get(:@stylesheet_compiler).
22
+ should be_instance_of TechnoGate::Contao::StylesheetCompiler
23
+ end
24
+ end
25
+
26
+ describe "#start" do
27
+ before :each do
28
+ subject.stub(:run_all)
29
+ end
30
+
31
+ it {should respond_to :start}
32
+
33
+ it "should call :run_all" do
34
+ subject.should_receive(:run_all).once
35
+
36
+ subject.start
37
+ end
38
+ end
39
+
40
+ describe '#run_all' do
41
+ before :each do
42
+ @stylesheet_compiler = mock('stylesheet_compiler', clean: true)
43
+ @coffeescript_compiler = mock('coffeescript_compiler', clean: true)
44
+ @javascript_compiler = mock('javascript_compiler', clean: true)
45
+
46
+ subject.instance_variable_set(:@stylesheet_compiler, @stylesheet_compiler)
47
+ subject.instance_variable_set(:@coffeescript_compiler, @coffeescript_compiler)
48
+ subject.instance_variable_set(:@javascript_compiler, @javascript_compiler)
49
+
50
+ subject.stub(:compile_stylesheet)
51
+ subject.stub(:compile_coffeescript)
52
+ subject.stub(:compile_javascript)
53
+ end
54
+
55
+ it {should respond_to :run_all}
56
+
57
+ it "Should clean assets" do
58
+ @stylesheet_compiler.should_receive(:clean).once.ordered
59
+ @coffeescript_compiler.should_receive(:clean).once.ordered
60
+ @javascript_compiler.should_receive(:clean).once.ordered
61
+
62
+ subject.run_all
63
+ end
64
+
65
+ it "Should recompile assets" do
66
+ subject.should_receive(:compile_stylesheet).once.ordered
67
+ subject.should_receive(:compile_coffeescript).once.ordered
68
+ subject.should_receive(:compile_javascript).once.ordered
69
+
70
+ subject.run_all
71
+ end
72
+ end
73
+
74
+ describe '#run_on_change' do
75
+ before :each do
76
+ @paths = mock('paths').as_null_object
77
+ end
78
+
79
+ it {should respond_to :run_on_change}
80
+
81
+ it "should call #compile" do
82
+ subject.should_receive(:compile).with(@paths).once
83
+
84
+ subject.send(:run_on_change, @paths)
85
+ end
86
+ end
87
+
88
+ describe '#run_on_deletion' do
89
+ before :each do
90
+ @paths = mock('paths').as_null_object
91
+ end
92
+
93
+ it {should respond_to :run_on_deletion}
94
+
95
+ it "should call #compile" do
96
+ subject.should_receive(:compile).with(@paths).once
97
+
98
+ subject.send(:run_on_deletion, @paths)
99
+ end
100
+ end
101
+
102
+ describe '#compile_stylesheet' do
103
+ before :each do
104
+ @stylesheet_compiler = mock('stylesheet_compiler', clean: true)
105
+
106
+ subject.instance_variable_set(:@stylesheet_compiler, @stylesheet_compiler)
107
+ end
108
+
109
+ it {should respond_to :compile_stylesheet}
110
+
111
+ it "should call @stylesheet_compiler.compile" do
112
+ @stylesheet_compiler.should_receive(:compile).once
113
+
114
+ subject.send :compile_stylesheet
115
+ end
116
+ end
117
+
118
+ describe '#compile_coffeescript' do
119
+ before :each do
120
+ @coffeescript_compiler = mock('coffeescript_compiler', clean: true, compile: true)
121
+
122
+ subject.instance_variable_set(:@coffeescript_compiler, @coffeescript_compiler)
123
+
124
+ subject.stub :compile_javascript
125
+ end
126
+
127
+ it {should respond_to :compile_coffeescript}
128
+
129
+ it "should call @coffeescript_compiler.compile" do
130
+ @coffeescript_compiler.should_receive(:compile).once
131
+
132
+ subject.send :compile_coffeescript
133
+ end
134
+ end
135
+
136
+ describe '#compile_javascript' do
137
+ before :each do
138
+ @javascript_compiler = mock('javascript_compiler', clean: true)
139
+
140
+ subject.instance_variable_set(:@javascript_compiler, @javascript_compiler)
141
+ end
142
+
143
+ it {should respond_to :compile_javascript}
144
+
145
+ it "should call @javascript_compiler.compile" do
146
+ @javascript_compiler.should_receive(:compile).once
147
+
148
+ subject.send :compile_javascript
149
+ end
150
+ end
151
+
152
+ describe '#compile' do
153
+ before :each do
154
+ subject.stub :compile_stylesheet
155
+ subject.stub :compile_coffeescript
156
+ subject.stub :compile_javascript
157
+ end
158
+
159
+ it "should call compile_stylesheet only if some stylesheet paths has changed" do
160
+ subject.should_receive(:compile_stylesheet).once
161
+
162
+ subject.send :compile, ["app/assets/stylesheets/file.css"]
163
+ end
164
+
165
+ it "should call compile_coffeescript only if some coffeescript paths has changed" do
166
+ subject.should_receive(:compile_coffeescript).once
167
+
168
+ subject.send :compile, ["app/assets/javascripts/file.js.coffee"]
169
+ end
170
+
171
+ it "should call compile_javascript only if some javascript paths has changed" do
172
+ subject.should_receive(:compile_javascript).once
173
+
174
+ subject.send :compile, ["app/assets/javascripts/file.js"]
175
+ end
176
+
177
+ it "should compile stylesheets only once" do
178
+ subject.should_receive(:compile_stylesheet).once
179
+
180
+ subject.send :compile, ["app/assets/stylesheets/file.css", "app/assets/stylesheets/file2.css"]
181
+ end
182
+
183
+ it "should compile coffeescripts only once" do
184
+ subject.should_receive(:compile_coffeescript).once
185
+
186
+ subject.send :compile, ["app/assets/javascripts/file.js.coffee", "app/assets/javascripts/file2.js.coffee"]
187
+ end
188
+
189
+ it "should compile javascripts only once" do
190
+ subject.should_receive(:compile_javascript).once
191
+
192
+ subject.send :compile, ["app/assets/javascripts/file.js", "app/assets/javascripts/file2.js"]
193
+ end
194
+
195
+ it "should compile javascript if coffeescript was used" do
196
+ subject.should_receive(:compile_javascript).once
197
+
198
+ subject.send :compile, ["app/assets/javascripts/file.js.coffee"]
199
+ end
200
+ end
201
+
202
+ describe "#file_in_path?" do
203
+ it "should return true" do
204
+ subject.send(:file_in_path?, "app/file.js", "app").should be_true
205
+ subject.send(:file_in_path?, "app/file.js", ["app"]).should be_true
206
+ end
207
+
208
+ it "should return false" do
209
+ subject.send(:file_in_path?, "app/file.js", "lib").should_not be_true
210
+ subject.send(:file_in_path?, "app/file.js", ["lib"]).should_not be_true
211
+ end
212
+ end
213
+
214
+ describe "#is_stylesheet?" do
215
+ it "should return true for stylesheet file" do
216
+ subject.send(:is_stylesheet?, "app/assets/stylesheets/file.css").should be_true
217
+ end
218
+
219
+ it "should return false for non-stylesheet files" do
220
+ subject.send(:is_stylesheet?, "app/assets/javascripts/file.css").should_not be_true
221
+ end
222
+ end
223
+
224
+ describe "#is_coffeescript?" do
225
+ it "should return true for coffeescript file" do
226
+ subject.send(:is_coffeescript?, "app/assets/javascripts/file.js.coffee").should be_true
227
+ end
228
+
229
+ it "should return false for non-coffeescript files" do
230
+ subject.send(:is_coffeescript?, "app/assets/stylesheets/file.css").should_not be_true
231
+ subject.send(:is_coffeescript?, "app/assets/stylesheets/file.js").should_not be_true
232
+ end
233
+ end
234
+
235
+ describe "#is_javascript?" do
236
+ it "should return true for javascript file" do
237
+ subject.send(:is_javascript?, "app/assets/javascripts/file.js").should be_true
238
+ end
239
+
240
+ it "should return false for non-coffeescript files" do
241
+ subject.send(:is_javascript?, "app/assets/stylesheets/file.css").should_not be_true
242
+ end
243
+ end
244
+ end
245
+ end
@@ -0,0 +1,42 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper.rb"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+
8
+ $: << File.expand_path('../../lib/contao.rb', __FILE__)
9
+
10
+ require 'active_support/core_ext/kernel/reporting'
11
+ require 'contao'
12
+ require 'fakefs/spec_helpers'
13
+
14
+ Dir["#{File.expand_path('../support', __FILE__)}/**/*.rb"].each {|f| require f}
15
+
16
+ RSpec.configure do |c|
17
+ c.treat_symbols_as_metadata_keys_with_true_values = true
18
+ c.run_all_when_everything_filtered = true
19
+ c.filter_run :focus
20
+
21
+ c.include FakeFS::SpecHelpers, :fakefs
22
+
23
+ c.before :each do
24
+ ::TechnoGate::Contao.env = @env = :development
25
+ ::TechnoGate::Contao.root = @root = "/root"
26
+ ::TechnoGate::Contao::Application.configure do
27
+ config.javascripts_path = ['vendor/assets/javascripts', 'lib/assets/javascripts', 'app/assets/javascripts']
28
+ config.stylesheets_path = 'app/assets/stylesheets'
29
+ config.images_path = 'app/assets/images'
30
+ config.contao_path = 'contao'
31
+ config.contao_public_path = 'public'
32
+ config.assets_public_path = 'public/resources'
33
+ end
34
+
35
+ silence_warnings do
36
+ ::Compass::Commands::UpdateProject = stub("Compass Update Project").as_null_object
37
+ ::Compass::Commands::CleanProject = stub("Compass Clea Project").as_null_object
38
+ ::Uglifier = stub("Uglifier").as_null_object
39
+ ::Guard::UI = stub('Guard UI').as_null_object
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,210 @@
1
+ shared_examples_for "Compiler" do
2
+ describe "attributes" do
3
+ it "should have :options as attr_accessor" do
4
+ subject.should respond_to(:options)
5
+ subject.should respond_to(:options=)
6
+ end
7
+ end
8
+
9
+ describe "init" do
10
+ it "should set options" do
11
+ subject.class.new(foo: :bar).options[:foo].should == :bar
12
+ end
13
+
14
+ it "should set the manifest_path as an instance variable" do
15
+ subject.instance_variable_get(:@manifest_path).should ==
16
+ Pathname('/root/public/resources/manifest.json')
17
+ end
18
+ end
19
+
20
+ describe "#compile" do
21
+ before :each do
22
+ subject.class.any_instance.stub(:prepare_folders)
23
+ subject.class.any_instance.stub(:compile_assets)
24
+ subject.class.any_instance.stub(:create_hashed_assets)
25
+ subject.class.any_instance.stub(:generate_manifest)
26
+ subject.class.any_instance.stub(:notify)
27
+ end
28
+
29
+ it {should respond_to :compile}
30
+
31
+ it "should be accessible at class level" do
32
+ subject.class.any_instance.should_receive(:compile).once
33
+ subject.class.compile
34
+ end
35
+
36
+ it "should return self" do
37
+ subject.compile.should == subject
38
+ end
39
+
40
+ it "should have the following call stack for development" do
41
+ subject.should_receive(:prepare_folders).once.ordered
42
+ subject.should_receive(:compile_assets).once.ordered
43
+ subject.should_receive(:generate_manifest).once.ordered
44
+ subject.should_receive(:notify).once.ordered
45
+
46
+ subject.compile
47
+ end
48
+
49
+ it "should have the following call stack for production" do
50
+ TechnoGate::Contao.env = :production
51
+ subject.should_receive(:prepare_folders).once.ordered
52
+ subject.should_receive(:compile_assets).once.ordered
53
+ subject.should_receive(:create_hashed_assets).once.ordered
54
+ subject.should_receive(:notify).once.ordered
55
+
56
+ subject.compile
57
+ end
58
+ end
59
+
60
+ describe "#clean", :fakefs do
61
+ it {should respond_to :clean}
62
+
63
+ it "should be accessible at class level" do
64
+ subject.class.any_instance.should_receive(:clean).once
65
+ subject.class.clean
66
+ end
67
+
68
+ it "should remove the entire assets_public_path" do
69
+ stub_filesystem!
70
+ File.directory?("/root/public/resources").should be_true
71
+ subject.clean
72
+ File.directory?("/root/public/resources").should be_false
73
+ end
74
+ end
75
+
76
+ describe "#prepare_folders", :fakefs do
77
+ it {should respond_to :prepare_folders}
78
+
79
+ it "should create the js_path" do
80
+ subject.send :prepare_folders
81
+ File.directory?("/root/public/resources")
82
+ end
83
+ end
84
+
85
+ describe "#compile_assets" do
86
+ it {should respond_to :compile_assets}
87
+ end
88
+
89
+ describe "#create_hashed_assets" do
90
+ it {should respond_to :create_hashed_assets}
91
+ end
92
+
93
+ describe '#create_digest_for_file', :fakefs do
94
+ before :each do
95
+ stub_filesystem!
96
+
97
+ @file_path = '/root/file.something.extension'
98
+ File.open(@file_path, 'w') do |f|
99
+ f.write('some data')
100
+ end
101
+
102
+ @digest = Digest::MD5.hexdigest('some data')
103
+ @digested_file_path = "/root/file.something-#{@digest}.extension"
104
+ end
105
+
106
+ it "should be able to create a hashed file" do
107
+ subject.send(:create_digest_for_file, @file_path)
108
+ File.exists?(@digested_file_path).should be_true
109
+ end
110
+
111
+ it "should have exactly the same content (a copy of the file)" do
112
+ subject.send(:create_digest_for_file, @file_path)
113
+ File.read(@digested_file_path).should == File.read(@file_path)
114
+ end
115
+ end
116
+
117
+ describe '#generate_manifest_for', :fakefs do
118
+ before :each do
119
+ stub_filesystem!
120
+
121
+ @files = [
122
+ '/root/public/resources/application.js',
123
+ '/root/public/resources/application-d41d8cd98f00b204e9800998ecf8427e.js',
124
+ '/root/public/resources/application.css',
125
+ '/root/public/resources/application-982436e5fe99465e0540d0cf38e7aff4.css',
126
+ ].each {|f| File.open(f, 'w') {|fh| fh.write ""}}
127
+
128
+ @manifest_path = '/root/public/resources/manifest.json'
129
+ end
130
+
131
+ describe "stylesheets" do
132
+ it "should a create a JSON manifest" do
133
+ subject.send(:generate_manifest_for, "stylesheets", "css")
134
+
135
+ File.exists?(@manifest_path).should be_true
136
+ end
137
+
138
+ it "should create a JSON manifest with only non-digested files if the env is development" do
139
+ subject.send(:generate_manifest_for, "stylesheets", "css")
140
+
141
+ manifest = JSON.parse(File.read(@manifest_path))
142
+ manifest.should have_key('stylesheets')
143
+ manifest['stylesheets'].should include('application.css')
144
+ manifest['stylesheets'].should_not include('application-982436e5fe99465e0540d0cf38e7aff4.css')
145
+ end
146
+
147
+ it "should create a JSON manifest with only the digested file if the env is production" do
148
+ TechnoGate::Contao.env = :production
149
+ subject.send(:generate_manifest_for, "stylesheets", "css")
150
+
151
+ manifest = JSON.parse(File.read(@manifest_path))
152
+ manifest.should have_key('stylesheets')
153
+ manifest['stylesheets'].should include('application-982436e5fe99465e0540d0cf38e7aff4.css')
154
+ manifest['stylesheets'].should_not include('application.css')
155
+ end
156
+
157
+ it "should not touch anything present in the manifest" do
158
+ File.open(@manifest_path, 'w') do |manifest|
159
+ manifest.write({"javascripts" => [1, 2, 3]}.to_json)
160
+ end
161
+
162
+ subject.send(:generate_manifest_for, "stylesheets", "css")
163
+
164
+ manifest = JSON.parse(File.read(@manifest_path))
165
+ manifest.should have_key('javascripts')
166
+ manifest["javascripts"].should == [1, 2, 3]
167
+ end
168
+ end
169
+
170
+ describe "javascripts" do
171
+
172
+ it "should a create a JSON manifest" do
173
+ subject.send(:generate_manifest_for, "javascripts", "js")
174
+
175
+ File.exists?(@manifest_path).should be_true
176
+ end
177
+
178
+ it "should create a JSON manifest with only non-digested files if the env is development" do
179
+ subject.send(:generate_manifest_for, "javascripts", "js")
180
+
181
+ manifest = JSON.parse(File.read(@manifest_path))
182
+ manifest.should have_key('javascripts')
183
+ manifest['javascripts'].should include('application.js')
184
+ manifest['javascripts'].should_not include('application-d41d8cd98f00b204e9800998ecf8427e.js')
185
+ end
186
+
187
+ it "should create a JSON manifest with only the digested file if the env is production" do
188
+ TechnoGate::Contao.env = :production
189
+ subject.send(:generate_manifest_for, "javascripts", "js")
190
+
191
+ manifest = JSON.parse(File.read(@manifest_path))
192
+ manifest.should have_key('javascripts')
193
+ manifest['javascripts'].should include('application-d41d8cd98f00b204e9800998ecf8427e.js')
194
+ manifest['javascripts'].should_not include('application.js')
195
+ end
196
+
197
+ it "should not touch anything present in the manifest" do
198
+ File.open(@manifest_path, 'w') do |manifest|
199
+ manifest.write({"stylesheets" => [1, 2, 3]}.to_json)
200
+ end
201
+
202
+ subject.send(:generate_manifest_for, "javascripts", "js")
203
+
204
+ manifest = JSON.parse(File.read(@manifest_path))
205
+ manifest.should have_key('stylesheets')
206
+ manifest["stylesheets"].should == [1, 2, 3]
207
+ end
208
+ end
209
+ end
210
+ end
@@ -0,0 +1,20 @@
1
+ def stub_filesystem!
2
+ [
3
+
4
+ '/root/app/assets/javascripts',
5
+ '/root/app/assets/stylesheets',
6
+ '/root/app/assets/images',
7
+ '/root/contao/non_existing_folder',
8
+ '/root/contao/system/modules/some_extension',
9
+ '/root/public/resources',
10
+ '/root/public/system/modules/frontend',
11
+ '/root/vendor/assets/javascripts',
12
+ '/tmp',
13
+
14
+ ].each do |folder|
15
+ FileUtils.mkdir_p folder
16
+ File.open("#{folder}/file.stub", 'w') do |f|
17
+ f.write "Stub file"
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ shared_examples_for "Singleton" do
2
+ it "should respond to :instance" do
3
+ klass.should respond_to :instance
4
+ end
5
+
6
+ it "should return an instance of the class" do
7
+ klass.instance.should be_instance_of klass
8
+ end
9
+
10
+ it "should raise an error trying to instantiate the class" do
11
+ expect { klass.new }.to raise_error NoMethodError
12
+ end
13
+
14
+ it "should be a singleton class" do
15
+ klass.instance.object_id.should == klass.instance.object_id
16
+ end
17
+ end