wagons 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +8 -8
  2. data/Rakefile +4 -6
  3. data/lib/generators/wagon/templates/%singular_name%.gemspec.tt +12 -11
  4. data/lib/generators/wagon/templates/{script → bin}/rails.tt +3 -2
  5. data/lib/generators/wagon/templates/config/routes.rb +1 -1
  6. data/lib/generators/wagon/templates/lib/%singular_name%/version.rb.tt +2 -2
  7. data/lib/generators/wagon/templates/lib/%singular_name%.rb.tt +0 -1
  8. data/lib/generators/wagon/wagon_generator.rb +4 -6
  9. data/lib/wagons/extensions/application.rb +2 -4
  10. data/lib/wagons/extensions/require_optional.rb +2 -2
  11. data/lib/wagons/extensions/test_case.rb +5 -7
  12. data/lib/wagons/installer.rb +52 -56
  13. data/lib/wagons/railtie.rb +2 -2
  14. data/lib/wagons/version.rb +1 -1
  15. data/lib/wagons/view_helper.rb +14 -16
  16. data/lib/wagons/wagon.rb +6 -8
  17. data/lib/wagons.rb +8 -10
  18. data/test/ci/rails3.gemfile.lock +108 -0
  19. data/test/dummy/Gemfile.lock +52 -48
  20. data/test/dummy/app/controllers/people_controller.rb +1 -3
  21. data/test/dummy/app/models/person.rb +1 -1
  22. data/test/dummy/config/application.rb +3 -4
  23. data/test/dummy/config/boot.rb +1 -1
  24. data/test/dummy/config/environments/development.rb +1 -1
  25. data/test/dummy/config/environments/production.rb +1 -1
  26. data/test/dummy/config/environments/test.rb +2 -2
  27. data/test/dummy/config/initializers/session_store.rb +1 -1
  28. data/test/dummy/config/initializers/wagon_app_version.rb +1 -1
  29. data/test/dummy/config/initializers/wrap_parameters.rb +1 -1
  30. data/test/dummy/config/routes.rb +3 -3
  31. data/test/dummy/db/development.sqlite3 +0 -0
  32. data/test/dummy/db/fixtures/development/people.rb +3 -3
  33. data/test/dummy/db/fixtures/test/people.rb +3 -3
  34. data/test/dummy/db/schema.rb +5 -5
  35. data/test/dummy/db/test.sqlite3 +0 -0
  36. data/test/dummy/log/development.log +1528 -1015
  37. data/test/dummy/log/test.log +11807 -6530
  38. data/test/dummy/test/models/person_test.rb +5 -5
  39. data/test/dummy/test/test_helper.rb +1 -1
  40. data/test/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  41. data/test/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  42. data/test/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  43. data/test/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  44. data/test/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  45. data/test/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  46. data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  47. data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  48. data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  49. data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  50. data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  51. data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  52. data/test/dummy/vendor/wagons/superliner/Gemfile.lock +53 -49
  53. data/test/dummy/vendor/wagons/superliner/app/controllers/cities_controller.rb +1 -2
  54. data/test/dummy/vendor/wagons/superliner/app/models/city.rb +2 -2
  55. data/test/dummy/vendor/wagons/superliner/db/fixtures/cities.rb +1 -1
  56. data/test/dummy/vendor/wagons/superliner/db/migrate/20120606125058_create_cities.rb +1 -1
  57. data/test/dummy/vendor/wagons/superliner/dummy_superliner.gemspec +11 -11
  58. data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner/version.rb +2 -2
  59. data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner/wagon.rb +3 -4
  60. data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner.rb +1 -1
  61. data/test/dummy/vendor/wagons/superliner/script/rails +1 -1
  62. data/test/dummy/vendor/wagons/superliner/test/controllers/cities_controller_test.rb +5 -7
  63. data/test/dummy/vendor/wagons/superliner/test/controllers/people_controller_test.rb +2 -4
  64. data/test/dummy/vendor/wagons/superliner/test/models/city_test.rb +3 -3
  65. data/test/dummy/vendor/wagons/superliner/test/models/person_test.rb +5 -7
  66. data/test/dummy/vendor/wagons/superliner/test/test_helper.rb +1 -2
  67. data/test/dummy/vendor/wagons/superliner/test/wagon_test.rb +23 -24
  68. data/test/test_helper.rb +5 -5
  69. data/test/wagons_installer_test.rb +72 -75
  70. data/test/wagons_test.rb +1 -1
  71. metadata +174 -160
@@ -1,85 +1,84 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class Wagons::InstallerTest < ActiveSupport::TestCase
4
-
5
4
  WAGONFILE = 'Wagonfile.test'
6
-
5
+
7
6
  attr_reader :installer
8
-
7
+
9
8
  setup :setup_gems, :stub_installer, :stub_wagons, :create_wagonfile
10
9
  teardown :remove_wagonfile
11
-
12
- test "available only returns latest versions" do
10
+
11
+ test 'available only returns latest versions' do
13
12
  assert_equal [@master2, @slave1, @superliner2], installer.available
14
13
  end
15
-
16
- test "not_installed does not return updates" do
14
+
15
+ test 'not_installed does not return updates' do
17
16
  assert_equal [@superliner2], installer.not_installed
18
17
  end
19
-
20
- test "updates returns higher versions" do
18
+
19
+ test 'updates returns higher versions' do
21
20
  assert_equal [@master2], installer.updates
22
21
  end
23
-
24
- test "find installed" do
22
+
23
+ test 'find installed' do
25
24
  assert_equal @master1, installer.installed_spec("#{app_name}_master")
26
25
  assert_nil installer.installed_spec("#{app_name}_superliner")
27
26
  end
28
-
29
- test "find available" do
27
+
28
+ test 'find available' do
30
29
  assert_equal @master2, installer.available_spec("#{app_name}_master")
31
30
  assert_equal @superliner2, installer.available_spec("#{app_name}_superliner")
32
31
  assert_nil installer.available_spec("#{app_name}_fantasy")
33
32
  end
34
-
35
- test "check app dependency is fine if app is sufficient" do
36
- installer.stubs(:wagon_class).with(@slave1).returns(stub(:app_requirement => Gem::Requirement.new('1.0')))
33
+
34
+ test 'check app dependency is fine if app is sufficient' do
35
+ installer.stubs(:wagon_class).with(@slave1).returns(stub(app_requirement: Gem::Requirement.new('1.0')))
37
36
  assert_equal [], installer.check_app_requirement([@master2, @slave1])
38
37
  end
39
-
40
- test "check app dependency fails if app is too old" do
41
- installer.stubs(:wagon_class).with(@superliner2).returns(stub(:app_requirement => Gem::Requirement.new('>= 2.0')))
38
+
39
+ test 'check app dependency fails if app is too old' do
40
+ installer.stubs(:wagon_class).with(@superliner2).returns(stub(app_requirement: Gem::Requirement.new('>= 2.0')))
42
41
  msg = installer.check_app_requirement([@master2, @superliner2])
43
42
  assert_equal 1, msg.size
44
- assert_match /requires/, msg.first
43
+ assert_match /requires/, msg.first
45
44
  end
46
-
47
- test "check dependencies is fine if all depts are installed at the same time" do
45
+
46
+ test 'check dependencies is fine if all depts are installed at the same time' do
48
47
  installer.stubs(:installed).returns([])
49
48
  assert_nil installer.check_dependencies([@master2, @superliner1])
50
49
  assert_nil installer.check_dependencies([@slave1, @master2])
51
50
  end
52
-
53
- test "check dependencies fails if dependency is missing" do
51
+
52
+ test 'check dependencies fails if dependency is missing' do
54
53
  installer.stubs(:installed).returns([])
55
54
  assert_match /requires/, installer.check_dependencies([@slave1])
56
55
  end
57
-
58
- test "check uninstalled dependencies is fine if all depts are uninstalled at the same time" do
56
+
57
+ test 'check uninstalled dependencies is fine if all depts are uninstalled at the same time' do
59
58
  assert_nil installer.check_uninstalled_dependencies([@slave1, @master1])
60
59
  end
61
-
62
- test "check uninstalled dependencies fails if dependency remains" do
60
+
61
+ test 'check uninstalled dependencies fails if dependency remains' do
63
62
  assert_match /requires/, installer.check_uninstalled_dependencies([@master1])
64
63
  end
65
-
66
- test "exclude specs does not modify original collection" do
64
+
65
+ test 'exclude specs does not modify original collection' do
67
66
  original = [@master2, @slave1, @superliner1]
68
67
  assert_equal [@master2], installer.exclude_specs(original, [@slave1, @superliner2])
69
68
  assert_equal [@master2, @slave1, @superliner1], original
70
69
  end
71
-
72
- test "specs from name" do
70
+
71
+ test 'specs from name' do
73
72
  assert_equal [@master2, @slave1], installer.specs_from_names(["#{app_name}_master", "#{app_name}_slave"])
74
73
  end
75
-
76
- test "specs_from_names raises exception if spec is not found" do
74
+
75
+ test 'specs_from_names raises exception if spec is not found' do
77
76
  assert_raise(RuntimeError) do
78
77
  installer.specs_from_names(["#{app_name}_master", "#{app_name}_fantasy", "#{app_name}_superliner"])
79
78
  end
80
79
  end
81
-
82
- test "wagonfile update updates version and add new entries" do
80
+
81
+ test 'wagonfile update updates version and add new entries' do
83
82
  installer.wagonfile_update([@master2, @slave1, @superliner2])
84
83
  content = File.read(WAGONFILE)
85
84
  assert_match /^gem '#{app_name}_master', '2.0.0'$/, content
@@ -87,8 +86,8 @@ class Wagons::InstallerTest < ActiveSupport::TestCase
87
86
  assert_match /^gem '#{app_name}_superliner', '2.0.0'$/, content
88
87
  assert_equal 3, content.each_line.count, content
89
88
  end
90
-
91
- test "wagonfile update keeps existing and add new entries if version should not be included in wagonfile" do
89
+
90
+ test 'wagonfile update keeps existing and add new entries if version should not be included in wagonfile' do
92
91
  installer.include_version_in_wagonfile = false
93
92
  installer.wagonfile_update([@master2, @slave1, @superliner2])
94
93
  content = File.read(WAGONFILE)
@@ -97,8 +96,8 @@ class Wagons::InstallerTest < ActiveSupport::TestCase
97
96
  assert_match /^gem '#{app_name}_superliner'$/, content
98
97
  assert_equal 3, content.each_line.count, content
99
98
  end
100
-
101
- test "wagonfile update updates commented gems" do
99
+
100
+ test 'wagonfile update updates commented gems' do
102
101
  File.open(WAGONFILE, 'w') do |f|
103
102
  f.puts "gem '#{app_name}_master', '1.0.0'"
104
103
  f.puts "# gem '#{app_name}_slave', '1.0.0'"
@@ -109,59 +108,59 @@ class Wagons::InstallerTest < ActiveSupport::TestCase
109
108
  assert_match /^gem '#{app_name}_slave', '1.0.0'$/, content
110
109
  assert_equal 2, content.each_line.count, content
111
110
  end
112
-
113
- test "wagonfile remove" do
111
+
112
+ test 'wagonfile remove' do
114
113
  installer.wagonfile_remove([@slave1])
115
114
  content = File.read(WAGONFILE)
116
115
  assert_match /^gem '#{app_name}_master', '1.0.0'$/, content
117
116
  assert_equal 1, content.each_line.count
118
117
  end
119
-
120
- test "install runs when checks are fine" do
121
- installer.stubs(:setup_command).returns("echo $RAILS_ENV > env.tmp")
118
+
119
+ test 'install runs when checks are fine' do
120
+ installer.stubs(:setup_command).returns('echo $RAILS_ENV > env.tmp')
122
121
  assert_nil installer.install(["#{app_name}_master"])
123
122
  content = File.read(WAGONFILE)
124
123
  assert_match /^gem '#{app_name}_master', '2.0.0'$/, content
125
124
  assert_equal 'test', File.read('env.tmp').strip
126
125
  File.delete('env.tmp')
127
126
  end
128
-
129
- test "install fails when setup command fails" do
127
+
128
+ test 'install fails when setup command fails' do
130
129
  installer.stubs(:setup_command).returns("echo $RAILS_ENV; echo 'its a bug' >&2; exit 1")
131
130
  assert_equal 'its a bug', installer.install(["#{app_name}_master"]).strip
132
131
  content = File.read(WAGONFILE)
133
132
  assert_match /^gem '#{app_name}_master', '1.0.0'$/, content
134
133
  end
135
-
136
- test "install fails when checks go wrong" do
137
- installer.stubs(:wagon_class).with(@superliner2).returns(stub(:app_requirement => Gem::Requirement.new('>= 2.0')))
134
+
135
+ test 'install fails when checks go wrong' do
136
+ installer.stubs(:wagon_class).with(@superliner2).returns(stub(app_requirement: Gem::Requirement.new('>= 2.0')))
138
137
  installer.expects(:wagonfile_edit).never
139
138
  assert_match /requires/, installer.install(["#{app_name}_superliner"])
140
139
  end
141
-
142
- test "install fails when name is invalid" do
140
+
141
+ test 'install fails when name is invalid' do
143
142
  installer.expects(:wagonfile_edit).never
144
143
  assert_match /not found/, installer.install(["#{app_name}_fantasy"])
145
144
  end
146
-
147
- test "uninstall runs when checks are fine" do
145
+
146
+ test 'uninstall runs when checks are fine' do
148
147
  installer.expects(:remove_wagons).once
149
148
  assert_nil installer.uninstall(["#{app_name}_master", "#{app_name}_slave"])
150
149
  content = File.read(WAGONFILE)
151
150
  assert content.blank?
152
151
  end
153
-
154
- test "uninstall fails when checks go wrong" do
152
+
153
+ test 'uninstall fails when checks go wrong' do
155
154
  installer.expects(:wagonfile_edit).never
156
155
  assert_match /requires/, installer.uninstall(["#{app_name}_master"])
157
156
  end
158
-
159
- test "uninstall fails when name is invalid" do
157
+
158
+ test 'uninstall fails when name is invalid' do
160
159
  installer.expects(:wagonfile_edit).never
161
160
  assert_match /not found/, installer.uninstall(["#{app_name}_fantasy"])
162
161
  end
163
-
164
- test "wagon class can load class from anywhere" do
162
+
163
+ test 'wagon class can load class from anywhere' do
165
164
  installer.unstub(:wagon_class)
166
165
  dir = File.expand_path('../dummy/vendor/wagons/superliner', __FILE__)
167
166
  spec = Gem::Specification.load(File.join(dir, 'dummy_superliner.gemspec'))
@@ -169,32 +168,32 @@ class Wagons::InstallerTest < ActiveSupport::TestCase
169
168
  assert_equal 'DummySuperliner::Wagon', installer.wagon_class(spec).name
170
169
  assert installer.wagon_class(spec).app_requirement.satisfied_by?(Gem::Version.new('1.0'))
171
170
  end
172
-
171
+
173
172
  private
174
-
173
+
175
174
  def setup_gems
176
175
  @master1 = gemspec('master', '1.0.0')
177
176
  @master2 = gemspec('master', '2.0.0')
178
177
  @slave1 = gemspec('slave', '1.0.0', 'master')
179
178
  @superliner1 = gemspec('superliner', '1.0.0')
180
179
  @superliner2 = gemspec('superliner', '2.0.0')
181
-
180
+
182
181
  Wagons.app_version = '1.0.0'
183
182
  end
184
-
183
+
185
184
  def stub_installer
186
185
  @installer = Wagons::Installer.new
187
186
  @installer.stubs(:load_available_specs).returns([@master1, @master2, @slave1, @superliner1, @superliner2])
188
187
  @installer.stubs(:installed).returns([@master1, @slave1])
189
188
  @installer.stubs(:wagonfile).returns(WAGONFILE)
190
189
  @installer.stubs(:remove_wagons).returns(nil)
191
- @installer.stubs(:wagon_class).returns(stub(:app_requirement => Gem::Requirement.new))
190
+ @installer.stubs(:wagon_class).returns(stub(app_requirement: Gem::Requirement.new))
192
191
  end
193
-
192
+
194
193
  def stub_wagons
195
194
  Wagons.stubs(:find).returns(stub(:protect? => false))
196
195
  end
197
-
196
+
198
197
  def create_wagonfile
199
198
  File.open(WAGONFILE, 'w') do |f|
200
199
  installer.installed.each do |spec|
@@ -202,24 +201,22 @@ class Wagons::InstallerTest < ActiveSupport::TestCase
202
201
  end
203
202
  end
204
203
  end
205
-
204
+
206
205
  def remove_wagonfile
207
- File.delete(WAGONFILE) if File.exists?(WAGONFILE)
206
+ File.delete(WAGONFILE) if File.exist?(WAGONFILE)
208
207
  end
209
-
208
+
210
209
  def app_name
211
210
  @app_name ||= Wagons.app_name
212
211
  end
213
-
212
+
214
213
  def gemspec(name, version, dependency = nil)
215
214
  Gem::Specification.new do |s|
216
215
  s.name = "#{app_name}_#{name}"
217
216
  s.version = version
218
217
  s.summary = 'blabla'
219
-
218
+
220
219
  s.add_dependency "#{app_name}_#{dependency}" if dependency
221
220
  end
222
221
  end
223
-
224
-
225
- end
222
+ end
data/test/wagons_test.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class WagonsTest < ActiveSupport::TestCase
4
- test "truth" do
4
+ test 'truth' do
5
5
  assert_kind_of Module, Wagons
6
6
  end
7
7
  end