rails_asset_packager 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/TODO ADDED
@@ -0,0 +1,11 @@
1
+ TODO
2
+ ====
3
+ * FEATURE: Add means to track which files that have been uploaded to S3 have been
4
+ modified to prevent uploading all assets every time you call
5
+ 'rake asset:cache:production.'
6
+ * BUG: Make it so that the asset:cache rake tasks execute properly when called
7
+ from other rake tasks outside rails_asset_packager rake file.
8
+ * FEATURE: Add capability to ignore assets already included in packaged assets
9
+ when uploading to S3.
10
+ * BUG: Fix inability to use the two helpers, stylesheet_link_merged and
11
+ javascript_include_merged. Start by fixing test suite.
@@ -1,3 +1,3 @@
1
1
  module RailsAssetPackager
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,21 +1,9 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
-
3
1
  ENV['RAILS_ENV'] = "development"
4
- require File.dirname(__FILE__) + '/../../../../config/environment'
5
- require 'test/unit'
6
- require 'rubygems'
7
- require 'mocha'
8
-
9
- require 'action_controller/test_process'
10
2
 
11
- ActionController::Base.logger = nil
12
- ActionController::Routing::Routes.reload rescue nil
3
+ $:.unshift(File.dirname(__FILE__))
4
+ require 'test_helper'
13
5
 
14
- class AssetPackageHelperDevelopmentTest < Test::Unit::TestCase
15
- include ActionController::Assertions::DomAssertions
16
- include ActionController::TestCase::Assertions
17
- include ActionView::Helpers::TagHelper
18
- include ActionView::Helpers::AssetTagHelper
6
+ class AssetPackageHelperDevelopmentTest < ActionView::TestCase
19
7
  include RailsAssetPackager::AssetPackageHelper
20
8
 
21
9
  def setup
@@ -23,49 +11,43 @@ class AssetPackageHelperDevelopmentTest < Test::Unit::TestCase
23
11
  RailsAssetPackager::AssetPackage.asset_packages_yml = YAML.load_file("#{Rails.root}/vendor/plugins/asset_packager/test/asset_packages.yml")
24
12
 
25
13
  RailsAssetPackager::AssetPackage.any_instance.stubs(:log)
26
-
27
- @controller = Class.new do
28
- def request
29
- @request ||= ActionController::TestRequest.new
30
- end
31
- end.new
32
14
  end
33
-
15
+
34
16
  def build_js_expected_string(*sources)
35
17
  sources.map {|s| javascript_include_tag(s) }.join("\n")
36
18
  end
37
-
19
+
38
20
  def build_css_expected_string(*sources)
39
21
  sources.map {|s| stylesheet_link_tag(s) }.join("\n")
40
22
  end
41
-
23
+
42
24
  def test_js_basic
43
25
  assert_dom_equal build_js_expected_string("prototype"),
44
26
  javascript_include_merged("prototype")
45
27
  end
46
28
 
47
29
  def test_js_multiple_packages
48
- assert_dom_equal build_js_expected_string("prototype", "foo"),
30
+ assert_dom_equal build_js_expected_string("prototype", "foo"),
49
31
  javascript_include_merged("prototype", "foo")
50
32
  end
51
-
33
+
52
34
  def test_js_unpackaged_file
53
- assert_dom_equal build_js_expected_string("prototype", "foo", "not_part_of_a_package"),
35
+ assert_dom_equal build_js_expected_string("prototype", "foo", "not_part_of_a_package"),
54
36
  javascript_include_merged("prototype", "foo", "not_part_of_a_package")
55
37
  end
56
-
38
+
57
39
  def test_js_multiple_from_same_package
58
- assert_dom_equal build_js_expected_string("prototype", "effects", "controls", "not_part_of_a_package", "foo"),
40
+ assert_dom_equal build_js_expected_string("prototype", "effects", "controls", "not_part_of_a_package", "foo"),
59
41
  javascript_include_merged("prototype", "effects", "controls", "not_part_of_a_package", "foo")
60
42
  end
61
43
 
62
44
  def test_js_by_package_name
63
- assert_dom_equal build_js_expected_string("prototype", "effects", "controls", "dragdrop"),
45
+ assert_dom_equal build_js_expected_string("prototype", "effects", "controls", "dragdrop"),
64
46
  javascript_include_merged(:base)
65
47
  end
66
-
48
+
67
49
  def test_js_multiple_package_names
68
- assert_dom_equal build_js_expected_string("prototype", "effects", "controls", "dragdrop", "foo", "bar", "application"),
50
+ assert_dom_equal build_js_expected_string("prototype", "effects", "controls", "dragdrop", "foo", "bar", "application"),
69
51
  javascript_include_merged(:base, :secondary)
70
52
  end
71
53
 
@@ -75,28 +57,28 @@ class AssetPackageHelperDevelopmentTest < Test::Unit::TestCase
75
57
  end
76
58
 
77
59
  def test_css_multiple_packages
78
- assert_dom_equal build_css_expected_string("screen", "foo", "subdir/bar"),
60
+ assert_dom_equal build_css_expected_string("screen", "foo", "subdir/bar"),
79
61
  stylesheet_link_merged("screen", "foo", "subdir/bar")
80
62
  end
81
-
63
+
82
64
  def test_css_unpackaged_file
83
- assert_dom_equal build_css_expected_string("screen", "foo", "not_part_of_a_package", "subdir/bar"),
65
+ assert_dom_equal build_css_expected_string("screen", "foo", "not_part_of_a_package", "subdir/bar"),
84
66
  stylesheet_link_merged("screen", "foo", "not_part_of_a_package", "subdir/bar")
85
67
  end
86
-
68
+
87
69
  def test_css_multiple_from_same_package
88
- assert_dom_equal build_css_expected_string("screen", "header", "not_part_of_a_package", "foo", "bar", "subdir/foo", "subdir/bar"),
70
+ assert_dom_equal build_css_expected_string("screen", "header", "not_part_of_a_package", "foo", "bar", "subdir/foo", "subdir/bar"),
89
71
  stylesheet_link_merged("screen", "header", "not_part_of_a_package", "foo", "bar", "subdir/foo", "subdir/bar")
90
72
  end
91
73
 
92
74
  def test_css_by_package_name
93
- assert_dom_equal build_css_expected_string("screen", "header"),
75
+ assert_dom_equal build_css_expected_string("screen", "header"),
94
76
  stylesheet_link_merged(:base)
95
77
  end
96
-
78
+
97
79
  def test_css_multiple_package_names
98
- assert_dom_equal build_css_expected_string("screen", "header", "foo", "bar", "subdir/foo", "subdir/bar"),
80
+ assert_dom_equal build_css_expected_string("screen", "header", "foo", "bar", "subdir/foo", "subdir/bar"),
99
81
  stylesheet_link_merged(:base, :secondary, "subdir/styles")
100
82
  end
101
-
83
+
102
84
  end
@@ -1,20 +1,9 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
1
+ ENV['RAILS_ENV'] = "production"
2
2
 
3
- require File.dirname(__FILE__) + '/../../../../config/environment'
4
- require 'test/unit'
5
- require 'rubygems'
6
- require 'mocha'
3
+ $:.unshift(File.dirname(__FILE__))
4
+ require 'test_helper'
7
5
 
8
- require 'action_controller/test_process'
9
-
10
- ActionController::Base.logger = nil
11
- ActionController::Routing::Routes.reload rescue nil
12
-
13
- class AssetPackageHelperProductionTest < Test::Unit::TestCase
14
- include ActionController::Assertions::DomAssertions
15
- include ActionController::TestCase::Assertions
16
- include ActionView::Helpers::TagHelper
17
- include ActionView::Helpers::AssetTagHelper
6
+ class AssetPackageHelperProductionTest < ActionView::TestCase
18
7
  include RailsAssetPackager::AssetPackageHelper
19
8
 
20
9
  cattr_accessor :packages_built
@@ -26,12 +15,6 @@ class AssetPackageHelperProductionTest < Test::Unit::TestCase
26
15
  RailsAssetPackager::AssetPackage.any_instance.stubs(:log)
27
16
  self.stubs(:should_merge?).returns(true)
28
17
 
29
- @controller = Class.new do
30
- def request
31
- @request ||= ActionController::TestRequest.new
32
- end
33
- end.new
34
-
35
18
  build_packages_once
36
19
  end
37
20
 
@@ -41,11 +24,11 @@ class AssetPackageHelperProductionTest < Test::Unit::TestCase
41
24
  @@packages_built = true
42
25
  end
43
26
  end
44
-
27
+
45
28
  def build_js_expected_string(*sources)
46
29
  sources.map {|s| javascript_include_tag(s) }.join("\n")
47
30
  end
48
-
31
+
49
32
  def build_css_expected_string(*sources)
50
33
  sources.map {|s| stylesheet_link_tag(s) }.join("\n")
51
34
  end
@@ -60,39 +43,39 @@ class AssetPackageHelperProductionTest < Test::Unit::TestCase
60
43
  current_file1 = RailsAssetPackager::AssetPackage.find_by_source("javascripts", "prototype").current_file
61
44
  current_file2 = RailsAssetPackager::AssetPackage.find_by_source("javascripts", "foo").current_file
62
45
 
63
- assert_dom_equal build_js_expected_string(current_file1, current_file2),
46
+ assert_dom_equal build_js_expected_string(current_file1, current_file2),
64
47
  javascript_include_merged("prototype", "foo")
65
48
  end
66
-
49
+
67
50
  def test_js_unpackaged_file
68
51
  current_file1 = RailsAssetPackager::AssetPackage.find_by_source("javascripts", "prototype").current_file
69
52
  current_file2 = RailsAssetPackager::AssetPackage.find_by_source("javascripts", "foo").current_file
70
-
71
- assert_dom_equal build_js_expected_string(current_file1, current_file2, "not_part_of_a_package"),
53
+
54
+ assert_dom_equal build_js_expected_string(current_file1, current_file2, "not_part_of_a_package"),
72
55
  javascript_include_merged("prototype", "foo", "not_part_of_a_package")
73
56
  end
74
-
57
+
75
58
  def test_js_multiple_from_same_package
76
59
  current_file1 = RailsAssetPackager::AssetPackage.find_by_source("javascripts", "prototype").current_file
77
60
  current_file2 = RailsAssetPackager::AssetPackage.find_by_source("javascripts", "foo").current_file
78
61
 
79
- assert_dom_equal build_js_expected_string(current_file1, "not_part_of_a_package", current_file2),
62
+ assert_dom_equal build_js_expected_string(current_file1, "not_part_of_a_package", current_file2),
80
63
  javascript_include_merged("prototype", "effects", "controls", "not_part_of_a_package", "foo")
81
64
  end
82
-
65
+
83
66
  def test_js_by_package_name
84
67
  package_name = RailsAssetPackager::AssetPackage.find_by_target("javascripts", "base").current_file
85
- assert_dom_equal build_js_expected_string(package_name),
68
+ assert_dom_equal build_js_expected_string(package_name),
86
69
  javascript_include_merged(:base)
87
70
  end
88
-
71
+
89
72
  def test_js_multiple_package_names
90
73
  package_name1 = RailsAssetPackager::AssetPackage.find_by_target("javascripts", "base").current_file
91
74
  package_name2 = RailsAssetPackager::AssetPackage.find_by_target("javascripts", "secondary").current_file
92
- assert_dom_equal build_js_expected_string(package_name1, package_name2),
75
+ assert_dom_equal build_js_expected_string(package_name1, package_name2),
93
76
  javascript_include_merged(:base, :secondary)
94
77
  end
95
-
78
+
96
79
  def test_css_basic
97
80
  current_file = RailsAssetPackager::AssetPackage.find_by_source("stylesheets", "screen").current_file
98
81
  assert_dom_equal build_css_expected_string(current_file),
@@ -104,39 +87,39 @@ class AssetPackageHelperProductionTest < Test::Unit::TestCase
104
87
  current_file2 = RailsAssetPackager::AssetPackage.find_by_source("stylesheets", "foo").current_file
105
88
  current_file3 = RailsAssetPackager::AssetPackage.find_by_source("stylesheets", "subdir/bar").current_file
106
89
 
107
- assert_dom_equal build_css_expected_string(current_file1, current_file2, current_file3),
90
+ assert_dom_equal build_css_expected_string(current_file1, current_file2, current_file3),
108
91
  stylesheet_link_merged("screen", "foo", "subdir/bar")
109
92
  end
110
-
93
+
111
94
  def test_css_unpackaged_file
112
95
  current_file1 = RailsAssetPackager::AssetPackage.find_by_source("stylesheets", "screen").current_file
113
96
  current_file2 = RailsAssetPackager::AssetPackage.find_by_source("stylesheets", "foo").current_file
114
-
115
- assert_dom_equal build_css_expected_string(current_file1, current_file2, "not_part_of_a_package"),
97
+
98
+ assert_dom_equal build_css_expected_string(current_file1, current_file2, "not_part_of_a_package"),
116
99
  stylesheet_link_merged("screen", "foo", "not_part_of_a_package")
117
100
  end
118
-
101
+
119
102
  def test_css_multiple_from_same_package
120
103
  current_file1 = RailsAssetPackager::AssetPackage.find_by_source("stylesheets", "screen").current_file
121
104
  current_file2 = RailsAssetPackager::AssetPackage.find_by_source("stylesheets", "foo").current_file
122
105
  current_file3 = RailsAssetPackager::AssetPackage.find_by_source("stylesheets", "subdir/bar").current_file
123
106
 
124
- assert_dom_equal build_css_expected_string(current_file1, "not_part_of_a_package", current_file2, current_file3),
107
+ assert_dom_equal build_css_expected_string(current_file1, "not_part_of_a_package", current_file2, current_file3),
125
108
  stylesheet_link_merged("screen", "header", "not_part_of_a_package", "foo", "bar", "subdir/foo", "subdir/bar")
126
109
  end
127
-
110
+
128
111
  def test_css_by_package_name
129
112
  package_name = RailsAssetPackager::AssetPackage.find_by_target("stylesheets", "base").current_file
130
- assert_dom_equal build_css_expected_string(package_name),
113
+ assert_dom_equal build_css_expected_string(package_name),
131
114
  stylesheet_link_merged(:base)
132
115
  end
133
-
116
+
134
117
  def test_css_multiple_package_names
135
118
  package_name1 = RailsAssetPackager::AssetPackage.find_by_target("stylesheets", "base").current_file
136
119
  package_name2 = RailsAssetPackager::AssetPackage.find_by_target("stylesheets", "secondary").current_file
137
120
  package_name3 = RailsAssetPackager::AssetPackage.find_by_target("stylesheets", "subdir/styles").current_file
138
- assert_dom_equal build_css_expected_string(package_name1, package_name2, package_name3),
121
+ assert_dom_equal build_css_expected_string(package_name1, package_name2, package_name3),
139
122
  stylesheet_link_merged(:base, :secondary, "subdir/styles")
140
123
  end
141
-
124
+
142
125
  end
@@ -1,10 +1,9 @@
1
- require File.dirname(__FILE__) + '/../../../../config/environment'
2
- require 'test/unit'
3
- require 'mocha'
1
+ $:.unshift(File.dirname(__FILE__))
2
+ require 'test_helper'
4
3
 
5
4
  class AssetPackagerTest < Test::Unit::TestCase
6
5
  include RailsAssetPackager
7
-
6
+
8
7
  def setup
9
8
  RailsAssetPackager::AssetPackage.asset_base_path = "#{Rails.root}/vendor/plugins/asset_packager/test/assets"
10
9
  RailsAssetPackager::AssetPackage.asset_packages_yml = YAML.load_file("#{Rails.root}/vendor/plugins/asset_packager/test/asset_packages.yml")
@@ -12,36 +11,36 @@ class AssetPackagerTest < Test::Unit::TestCase
12
11
  RailsAssetPackager::AssetPackage.any_instance.stubs(:log)
13
12
  RailsAssetPackager::AssetPackage.build_all
14
13
  end
15
-
14
+
16
15
  def teardown
17
16
  RailsAssetPackager::AssetPackage.delete_all
18
17
  end
19
-
18
+
20
19
  def test_find_by_type
21
20
  js_asset_packages = RailsAssetPackager::AssetPackage.find_by_type("javascripts")
22
21
  assert_equal 2, js_asset_packages.length
23
22
  assert_equal "base", js_asset_packages[0].target
24
23
  assert_equal ["prototype", "effects", "controls", "dragdrop"], js_asset_packages[0].sources
25
24
  end
26
-
25
+
27
26
  def test_find_by_target
28
27
  package = RailsAssetPackager::AssetPackage.find_by_target("javascripts", "base")
29
28
  assert_equal "base", package.target
30
29
  assert_equal ["prototype", "effects", "controls", "dragdrop"], package.sources
31
30
  end
32
-
31
+
33
32
  def test_find_by_source
34
33
  package = RailsAssetPackager::AssetPackage.find_by_source("javascripts", "controls")
35
34
  assert_equal "base", package.target
36
35
  assert_equal ["prototype", "effects", "controls", "dragdrop"], package.sources
37
36
  end
38
-
37
+
39
38
  def test_delete_and_build
40
39
  RailsAssetPackager::AssetPackage.delete_all
41
40
  js_package_names = Dir.new("#{RailsAssetPackager::AssetPackage.asset_base_path}/javascripts").entries.delete_if { |x| ! (x =~ /\A\w+_packaged.js/) }
42
41
  css_package_names = Dir.new("#{RailsAssetPackager::AssetPackage.asset_base_path}/stylesheets").entries.delete_if { |x| ! (x =~ /\A\w+_packaged.css/) }
43
42
  css_subdir_package_names = Dir.new("#{RailsAssetPackager::AssetPackage.asset_base_path}/stylesheets/subdir").entries.delete_if { |x| ! (x =~ /\A\w+_packaged.css/) }
44
-
43
+
45
44
  assert_equal 0, js_package_names.length
46
45
  assert_equal 0, css_package_names.length
47
46
  assert_equal 0, css_subdir_package_names.length
@@ -50,7 +49,7 @@ class AssetPackagerTest < Test::Unit::TestCase
50
49
  js_package_names = Dir.new("#{RailsAssetPackager::AssetPackage.asset_base_path}/javascripts").entries.delete_if { |x| ! (x =~ /\A\w+_packaged.js/) }.sort
51
50
  css_package_names = Dir.new("#{RailsAssetPackager::AssetPackage.asset_base_path}/stylesheets").entries.delete_if { |x| ! (x =~ /\A\w+_packaged.css/) }.sort
52
51
  css_subdir_package_names = Dir.new("#{RailsAssetPackager::AssetPackage.asset_base_path}/stylesheets/subdir").entries.delete_if { |x| ! (x =~ /\A\w+_packaged.css/) }.sort
53
-
52
+
54
53
  assert_equal 2, js_package_names.length
55
54
  assert_equal 2, css_package_names.length
56
55
  assert_equal 1, css_subdir_package_names.length
@@ -60,7 +59,7 @@ class AssetPackagerTest < Test::Unit::TestCase
60
59
  assert css_package_names[1].match(/\Asecondary_packaged.css\z/)
61
60
  assert css_subdir_package_names[0].match(/\Astyles_packaged.css\z/)
62
61
  end
63
-
62
+
64
63
  def test_js_names_from_sources
65
64
  package_names = RailsAssetPackager::AssetPackage.targets_from_sources("javascripts", ["prototype", "effects", "noexist1", "controls", "foo", "noexist2"])
66
65
  assert_equal 4, package_names.length
@@ -69,7 +68,7 @@ class AssetPackagerTest < Test::Unit::TestCase
69
68
  assert package_names[2].match(/\Asecondary_packaged\z/)
70
69
  assert_equal package_names[3], "noexist2"
71
70
  end
72
-
71
+
73
72
  def test_css_names_from_sources
74
73
  package_names = RailsAssetPackager::AssetPackage.targets_from_sources("stylesheets", ["header", "screen", "noexist1", "foo", "noexist2"])
75
74
  assert_equal 4, package_names.length
@@ -78,7 +77,7 @@ class AssetPackagerTest < Test::Unit::TestCase
78
77
  assert package_names[2].match(/\Asecondary_packaged\z/)
79
78
  assert_equal package_names[3], "noexist2"
80
79
  end
81
-
80
+
82
81
  def test_should_return_merge_environments_when_set
83
82
  RailsAssetPackager::AssetPackage.merge_environments = ["staging", "production"]
84
83
  assert_equal ["staging", "production"], RailsAssetPackager::AssetPackage.merge_environments
@@ -87,5 +86,5 @@ class AssetPackagerTest < Test::Unit::TestCase
87
86
  def test_should_only_return_production_merge_environment_when_not_set
88
87
  assert_equal ["production"], RailsAssetPackager::AssetPackage.merge_environments
89
88
  end
90
-
89
+
91
90
  end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.expand_path('../lib', __FILE__))
2
+ require File.dirname(__FILE__) + '/../../../../config/environment'
3
+
4
+ require 'rails/test_help'
5
+ require 'mocha'
6
+
7
+ ActionController::Base.logger = nil
8
+ ActionController::Routing::Routes.reload rescue nil
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_asset_packager
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 1
10
- version: 0.1.1
9
+ - 2
10
+ version: 0.1.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Scott Becker
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-01-18 00:00:00 -06:00
20
+ date: 2011-01-25 00:00:00 -06:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,7 @@ files:
82
82
  - Gemfile.lock
83
83
  - README
84
84
  - Rakefile
85
+ - TODO
85
86
  - lib/jsmin.rb
86
87
  - lib/rails_asset_packager.rb
87
88
  - lib/rails_asset_packager/asset_package.rb
@@ -108,6 +109,7 @@ files:
108
109
  - test/assets/stylesheets/screen.css
109
110
  - test/assets/stylesheets/subdir/bar.css
110
111
  - test/assets/stylesheets/subdir/foo.css
112
+ - test/test_helper.rb
111
113
  has_rdoc: true
112
114
  homepage: http://rubygems.org/gems/rails_asset_packager
113
115
  licenses: []
@@ -160,3 +162,4 @@ test_files:
160
162
  - test/assets/stylesheets/screen.css
161
163
  - test/assets/stylesheets/subdir/bar.css
162
164
  - test/assets/stylesheets/subdir/foo.css
165
+ - test/test_helper.rb