rapid-core 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (132) hide show
  1. data/.gitignore +7 -0
  2. data/.rspec +2 -0
  3. data/Gemfile +11 -0
  4. data/Gemfile.lock +53 -0
  5. data/Rakefile +61 -0
  6. data/cucumber.yml +3 -0
  7. data/doc/plan.txt +89 -0
  8. data/doc/scaffold/controller.rb +83 -0
  9. data/doc/scaffold/helper.rb +2 -0
  10. data/doc/scaffold/model.rb +5 -0
  11. data/doc/scaffold/rapid_scaffold.rb +5 -0
  12. data/doc/scaffold/views/_form.html.erb +25 -0
  13. data/doc/scaffold/views/edit.html.erb +6 -0
  14. data/doc/scaffold/views/index.html.erb +25 -0
  15. data/doc/scaffold/views/new.html.erb +5 -0
  16. data/doc/scaffold/views/show.html.erb +15 -0
  17. data/features/settings/boolean/default.feature +36 -0
  18. data/features/settings/double-nested/default.feature +50 -0
  19. data/features/settings/double-nested/if.feature +41 -0
  20. data/features/settings/double-nested/unless.feature +39 -0
  21. data/features/settings/double-nested/validates/exclusion_of.feature +30 -0
  22. data/features/settings/double-nested/validates/format_of.feature +30 -0
  23. data/features/settings/double-nested/validates/inclusion_of.feature +30 -0
  24. data/features/settings/double-nested/validates/length_of.feature +30 -0
  25. data/features/settings/double-nested/validates/presence_of.feature +37 -0
  26. data/features/settings/double-nested/validates/size_of.feature +30 -0
  27. data/features/settings/integer/default.feature +49 -0
  28. data/features/settings/nested/default.feature +50 -0
  29. data/features/settings/nested/if.feature +53 -0
  30. data/features/settings/nested/unless.feature +32 -0
  31. data/features/settings/nested/validates/exclusion_of.feature +30 -0
  32. data/features/settings/nested/validates/format_of.feature +30 -0
  33. data/features/settings/nested/validates/inclusion_of.feature +30 -0
  34. data/features/settings/nested/validates/length_of.feature +30 -0
  35. data/features/settings/nested/validates/presence_of.feature +37 -0
  36. data/features/settings/nested/validates/size_of.feature +30 -0
  37. data/features/settings/not_found.feature +33 -0
  38. data/features/settings/string/default.feature +36 -0
  39. data/features/settings/string/validates/exclusion_of.feature +30 -0
  40. data/features/settings/string/validates/format_of.feature +30 -0
  41. data/features/settings/string/validates/inclusion_of.feature +30 -0
  42. data/features/settings/string/validates/length_of.feature +30 -0
  43. data/features/settings/string/validates/presence_of.feature +37 -0
  44. data/features/settings/string/validates/size_of.feature +30 -0
  45. data/features/step_definitions/settings_steps.rb +92 -0
  46. data/features/step_definitions/skeleton_steps.rb +68 -0
  47. data/features/step_definitions/template_steps.rb +39 -0
  48. data/features/support/env.rb +6 -0
  49. data/features/templates/comment_if.feature +55 -0
  50. data/features/templates/comment_unless.feature +56 -0
  51. data/features/templates/for/for.feature +51 -0
  52. data/features/templates/if/else.feature +60 -0
  53. data/features/templates/if/elsif.feature +82 -0
  54. data/features/templates/if/if.feature +55 -0
  55. data/features/templates/namespaces/exist.feature +54 -0
  56. data/features/templates/static.feature +37 -0
  57. data/features/templates/variables.feature +61 -0
  58. data/lib/rapid/check.rb +162 -0
  59. data/lib/rapid/core.rb +37 -0
  60. data/lib/rapid/error.rb +84 -0
  61. data/lib/rapid/module.rb +35 -0
  62. data/lib/rapid/railtie.rb +18 -0
  63. data/lib/rapid/setting/base.rb +35 -0
  64. data/lib/rapid/setting/boolean_setting.rb +17 -0
  65. data/lib/rapid/setting/class_hash.rb +34 -0
  66. data/lib/rapid/setting/comments.rb +25 -0
  67. data/lib/rapid/setting/definer.rb +151 -0
  68. data/lib/rapid/setting/instance_hash.rb +132 -0
  69. data/lib/rapid/setting/instance_root.rb +107 -0
  70. data/lib/rapid/setting/integer_setting.rb +24 -0
  71. data/lib/rapid/setting/namespace/base.rb +113 -0
  72. data/lib/rapid/setting/namespace/instance.rb +84 -0
  73. data/lib/rapid/setting/nested_validations.rb +86 -0
  74. data/lib/rapid/setting/string_setting.rb +13 -0
  75. data/lib/rapid/settings.rb +129 -0
  76. data/lib/rapid/skeleton/base.rb +164 -0
  77. data/lib/rapid/skeleton/helpers/directory.rb +53 -0
  78. data/lib/rapid/skeleton/helpers/gem.rb +133 -0
  79. data/lib/rapid/skeleton/helpers/migration.rb +46 -0
  80. data/lib/rapid/skeleton/helpers/route.rb +115 -0
  81. data/lib/rapid/skeleton/helpers/script.rb +33 -0
  82. data/lib/rapid/skeleton/helpers/template.rb +73 -0
  83. data/lib/rapid/skeleton/helpers/view.rb +35 -0
  84. data/lib/rapid/spec/template.rb +104 -0
  85. data/lib/rapid/spec.rb +1 -0
  86. data/lib/rapid/tasks.rb +29 -0
  87. data/lib/rapid/template/base.rb +49 -0
  88. data/lib/rapid/template/node/base.rb +43 -0
  89. data/lib/rapid/template/node/comment_node.rb +42 -0
  90. data/lib/rapid/template/node/if_node.rb +109 -0
  91. data/lib/rapid/template/node/root.rb +51 -0
  92. data/lib/rapid/template/node/static.rb +29 -0
  93. data/lib/rapid/template/node/variable.rb +86 -0
  94. data/lib/rapid/template/parser.rb +167 -0
  95. data/lib/rapid/template/pulling/base.rb +91 -0
  96. data/lib/rapid/template/pulling/explicit.rb +92 -0
  97. data/lib/rapid/template/pulling/forgiving.rb +58 -0
  98. data/lib/rapid/version.rb +3 -0
  99. data/lib/rapid.rb +37 -0
  100. data/rapid-core.gemspec +26 -0
  101. data/spec/rapid/check_spec.rb +119 -0
  102. data/spec/rapid/error_spec.rb +14 -0
  103. data/spec/rapid/module_spec.rb +28 -0
  104. data/spec/rapid/setting/base_spec.rb +17 -0
  105. data/spec/rapid/setting/definer_spec.rb +318 -0
  106. data/spec/rapid/setting/instance_root_spec.rb +161 -0
  107. data/spec/rapid/setting/namespace/base_spec.rb +93 -0
  108. data/spec/rapid/setting/namespace/instance_spec.rb +12 -0
  109. data/spec/rapid/setting/nested_validations_spec.rb +72 -0
  110. data/spec/rapid/settings_spec.rb +51 -0
  111. data/spec/rapid/skeleton/base_spec.rb +224 -0
  112. data/spec/rapid/skeleton/helpers/directory_spec.rb +104 -0
  113. data/spec/rapid/skeleton/helpers/gem_spec.rb +180 -0
  114. data/spec/rapid/skeleton/helpers/migration_spec.rb +23 -0
  115. data/spec/rapid/skeleton/helpers/route_spec.rb +120 -0
  116. data/spec/rapid/skeleton/helpers/script_spec.rb +57 -0
  117. data/spec/rapid/skeleton/helpers/template_spec.rb +142 -0
  118. data/spec/rapid/skeleton/helpers/view_spec.rb +54 -0
  119. data/spec/rapid/spec/template_spec.rb +168 -0
  120. data/spec/rapid/template/base_spec.rb +290 -0
  121. data/spec/rapid/template/node/base_spec.rb +9 -0
  122. data/spec/rapid/template/node/comment_node_spec.rb +46 -0
  123. data/spec/rapid/template/node/if_node_spec.rb +28 -0
  124. data/spec/rapid/template/node/root_spec.rb +9 -0
  125. data/spec/rapid/template/node/static_spec.rb +17 -0
  126. data/spec/rapid/template/node/variable_spec.rb +87 -0
  127. data/spec/rapid/template/parser_spec.rb +187 -0
  128. data/spec/rapid/template/pulling/base_spec.rb +81 -0
  129. data/spec/rapid/template/pulling/explicit_spec.rb +33 -0
  130. data/spec/rapid/template/pulling/forgiving_spec.rb +132 -0
  131. data/spec/spec_helper.rb +10 -0
  132. metadata +325 -0
@@ -0,0 +1,224 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Rapid::Skeleton::Base do
4
+
5
+ describe "project_path" do
6
+
7
+ it "should accept it as a parameter" do
8
+ @skeleton = Rapid::Skeleton::Base.new nil, :project_path => "/foo"
9
+ @skeleton.project_path.should == "/foo"
10
+ end
11
+
12
+ it "should default to the application root" do
13
+ @skeleton = Rapid::Skeleton::Base.new
14
+ @skeleton.project_path.should == File.expand_path('.')
15
+ end
16
+
17
+ end
18
+
19
+ describe "templates_path" do
20
+
21
+ after do
22
+ FileUtils.rm_rf "tmp/test/lib"
23
+ FileUtils.rm_rf "tmp/test/templates"
24
+ end
25
+
26
+ it "should accept it as a parameter" do
27
+ @skeleton = Rapid::Skeleton::Base.new nil, :templates_path => "foo"
28
+ @skeleton.templates_path.should == "foo"
29
+ end
30
+
31
+ it "should discover the templates path given a file" do
32
+ FileUtils.mkdir_p "tmp/test/lib/rapid/app"
33
+ FileUtils.mkdir_p "tmp/test/templates"
34
+ @skeleton = Rapid::Skeleton::Base.new nil, :file => "tmp/test/lib/rapid/app/skeleton.rb"
35
+ @skeleton.templates_path.should == "tmp/test/templates"
36
+ end
37
+
38
+ end
39
+
40
+ describe "valid?" do
41
+
42
+ it "should check with the settings" do
43
+ @settings = mock('settings')
44
+ @settings.should_receive(:valid?).with.and_return(false)
45
+ @settings.should_receive(:errors).with.and_return('name' => ["can't be blank"])
46
+
47
+ @skeleton = Rapid::Skeleton::Base.new @settings
48
+ @skeleton.valid?.should be_false
49
+ @skeleton.errors.full_messages.should == ["Name can't be blank"]
50
+ end
51
+
52
+ end
53
+
54
+ describe "settings=" do
55
+
56
+ it "should accept a hash and load the settings with it" do
57
+ @settings = mock('settings')
58
+ @settings.should_receive(:load_hash).with(:foo => "bar")
59
+
60
+ @skeleton = Rapid::Skeleton::Base.new @settings
61
+ @skeleton.settings = {:foo => "bar"}
62
+ end
63
+
64
+ end
65
+
66
+ describe "push" do
67
+
68
+ it "should know whether it's pushing" do
69
+ @skeleton = Rapid::Skeleton::Base.new
70
+
71
+ @skeleton.send(:pushing?).should == false
72
+ end
73
+
74
+ it "should raise a not implemented error" do
75
+ @skeleton = Rapid::Skeleton::Base.new
76
+ lambda { @skeleton.push }.should raise_error(NotImplementedError)
77
+ end
78
+
79
+ end
80
+
81
+ describe "push!" do
82
+
83
+ it "should raise an error if the skeleton is not valid" do
84
+ @skeleton = Rapid::Skeleton::Base.new
85
+ @skeleton.should_receive(:valid?).and_return(false)
86
+
87
+ lambda { @skeleton.push! }.should raise_error(Rapid::InvalidSkeletonError)
88
+ end
89
+
90
+ it "should push if valid" do
91
+ @skeleton = Rapid::Skeleton::Base.new
92
+ @skeleton.should_receive(:valid?).and_return(true)
93
+ @skeleton.should_receive(:bones).with.and_return(true)
94
+
95
+ @skeleton.push!
96
+ end
97
+
98
+ end
99
+
100
+ describe "pull" do
101
+
102
+ it "should know whether it's pulling" do
103
+ @skeleton = Rapid::Skeleton::Base.new
104
+
105
+ @skeleton.send(:pulling?).should == false
106
+ end
107
+
108
+ it "should raise a not implemented error" do
109
+ @skeleton = Rapid::Skeleton::Base.new
110
+ lambda { @skeleton.pull }.should raise_error(NotImplementedError)
111
+ end
112
+
113
+ it "should return true if it does not encounter an error" do
114
+ @skeleton = Rapid::Skeleton::Base.new
115
+ @skeleton.should_receive(:bones).and_return
116
+
117
+ @skeleton.pull.should == true
118
+ end
119
+
120
+ it "should return false if it does not encounter an error" do
121
+ @skeleton = Rapid::Skeleton::Base.new
122
+ Rapid::Check.should_receive(:encounters_error?).and_return(true)
123
+
124
+ @skeleton.pull.should == false
125
+ end
126
+
127
+ end
128
+
129
+ describe "pull!" do
130
+
131
+ it "should raise an error if the pull fails" do
132
+ @skeleton = Rapid::Skeleton::Base.new
133
+ @skeleton.should_receive(:pull).and_return(false)
134
+
135
+ lambda { @skeleton.pull! }.should raise_error(Rapid::InvalidSkeletonError)
136
+ end
137
+
138
+ it "should not raise an error if the pull succeeds" do
139
+ @skeleton = Rapid::Skeleton::Base.new
140
+ @skeleton.should_receive(:pull).and_return(true)
141
+
142
+ @skeleton.pull!
143
+ end
144
+
145
+ end
146
+
147
+ describe "logging" do
148
+
149
+ before do
150
+ @check = Rapid::Check.new ""
151
+ Rapid::Check.current = @check
152
+
153
+ @skeleton = Rapid::Skeleton::Base.new
154
+ end
155
+
156
+ after do
157
+ Rapid::Check.current = nil
158
+ end
159
+
160
+ it "should raise an error if Rapid::Check.current is nil" do
161
+ Rapid::Check.current = nil
162
+ lambda { @skeleton.send(:ok, 'foo', 'bar') }.should raise_error
163
+ end
164
+
165
+ it "should delegate ok to Rapid::Check.current" do
166
+ @check.should_receive(:ok).with('foo', 'bar')
167
+ @skeleton.send(:ok, 'foo', 'bar')
168
+ end
169
+
170
+ it "should delegate warning to Rapid::Check.current" do
171
+ @check.should_receive(:warning).with('foo', 'bar')
172
+ @skeleton.send(:warning, 'foo', 'bar')
173
+ end
174
+
175
+ it "should delegate error to Rapid::Check.current" do
176
+ @check.should_receive(:error).with('foo', 'bar')
177
+ @skeleton.send(:error, 'foo', 'bar')
178
+ end
179
+
180
+ it "should delegate error to Rapid::Check.current" do
181
+ @check.should_receive(:exception).with('foo', 'bar')
182
+ @skeleton.send(:exception, 'foo', 'bar')
183
+ end
184
+
185
+ end
186
+
187
+ describe "section" do
188
+
189
+ after do
190
+ Rapid::Check.current = nil
191
+ end
192
+
193
+ it "should work with Rapid::Check.current" do
194
+ @check = Rapid::Check.new ""
195
+ Rapid::Check.current = @check
196
+
197
+ @skeleton = Rapid::Skeleton::Base.new
198
+ @skeleton.send(:section, "foo") do
199
+ @skeleton.send :ok, "hi", "hey"
200
+ end
201
+ end
202
+
203
+ it "should work without Rapid::Check.current" do
204
+ @skeleton = Rapid::Skeleton::Base.new
205
+ @skeleton.send(:section, "foo") do
206
+
207
+ end
208
+ end
209
+
210
+ it "should work without a block" do
211
+ @skeleton = Rapid::Skeleton::Base.new
212
+ @skeleton.should_receive(:foo)
213
+ @skeleton.send(:section, "foo")
214
+ end
215
+
216
+ it "should work without a block and an option" do
217
+ @skeleton = Rapid::Skeleton::Base.new
218
+ @skeleton.should_receive(:bar)
219
+ @skeleton.send(:section, "foo", :method => "bar")
220
+ end
221
+
222
+ end
223
+
224
+ end
@@ -0,0 +1,104 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe Rapid::Skeleton::Helpers::Directory do
4
+
5
+ before do
6
+ Object.class_eval do
7
+ class MyClass
8
+ include Rapid::Skeleton::Helpers::Directory
9
+
10
+ attr_accessor :templates_path, :project_path, :get_binding
11
+ end
12
+ end
13
+
14
+ @instance = MyClass.new
15
+ end
16
+
17
+ after do
18
+ Object.send(:remove_const, :MyClass) rescue nil
19
+ end
20
+
21
+ describe "push_directory" do
22
+
23
+ before do
24
+ @instance.project_path = 'tmp'
25
+ @instance.stub!(:pushing?).and_return(true)
26
+ @instance.stub!(:pulling?).and_return(false)
27
+ end
28
+
29
+ it "should create the directory" do
30
+ FileUtils.should_receive(:mkdir_p).with('tmp/foo/bar')
31
+
32
+ @instance.send :directory, 'foo/bar'
33
+ end
34
+
35
+ it "shouldn't push the directory if setting is false" do
36
+ FileUtils.should_not_receive(:mkdir_p)
37
+
38
+ @instance.should_receive(:set?).with('foo').and_return(false)
39
+ @instance.send :directory, 'foo/bar', :if => 'foo'
40
+ end
41
+
42
+ it "should push the directory if the setting is true" do
43
+ FileUtils.should_receive(:mkdir_p).with('tmp/foo/bar')
44
+
45
+ @instance.should_receive(:set?).with('foo').and_return(true)
46
+ @instance.send :directory, 'foo/bar', :if => 'foo'
47
+ end
48
+
49
+ end
50
+
51
+ describe "pull_directory" do
52
+
53
+ before do
54
+ @instance.project_path = 'tmp/test'
55
+
56
+ @instance.stub!(:pushing?).and_return(false)
57
+ @instance.stub!(:pulling?).and_return(true)
58
+ end
59
+
60
+ after do
61
+ FileUtils.rm_rf 'tmp/test'
62
+ end
63
+
64
+ it "should warn when the directory does not exist" do
65
+ @instance.should_receive(:warning).with('foo/bar', "doesn't exist")
66
+
67
+ @instance.send :directory, 'foo/bar'
68
+ end
69
+
70
+ it "should error when the directory is just a file" do
71
+ FileUtils.mkdir_p('tmp/test/foo')
72
+ File.open('tmp/test/foo/bar', 'w') {|f| f.write "hi"}
73
+
74
+ @instance.should_receive(:error).with('foo/bar', "isn't a directory")
75
+
76
+ @instance.send :directory, 'foo/bar'
77
+ end
78
+
79
+ it "should report ok when directory exists" do
80
+ FileUtils.mkdir_p('tmp/test/foo')
81
+
82
+ @instance.should_receive(:ok).with('foo', "is good")
83
+
84
+ @instance.send :directory, 'foo'
85
+ end
86
+
87
+ it "should set the 'if' setting false" do
88
+ @instance.should_receive(:ok).with('foo', "doesn't exist")
89
+ @instance.should_receive(:[]=).with('foo', false)
90
+
91
+ @instance.send :directory, 'foo', :if => 'foo'
92
+ end
93
+
94
+ it "should set the 'if' setting true" do
95
+ FileUtils.mkdir_p('tmp/test/foo')
96
+ @instance.should_receive(:ok).with('foo', "is good")
97
+ @instance.should_receive(:[]=).with('foo', true)
98
+
99
+ @instance.send :directory, 'foo', :if => 'foo'
100
+ end
101
+
102
+ end
103
+
104
+ end
@@ -0,0 +1,180 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe Rapid::Skeleton::Helpers::Gem do
4
+
5
+ before do
6
+ Object.class_eval do
7
+ class MyClass
8
+ include ActiveModel::Validations
9
+ include Rapid::Skeleton::Helpers::Gem
10
+
11
+ attr_accessor :templates_path, :project_path, :get_binding
12
+ end
13
+ end
14
+ end
15
+
16
+ after do
17
+ Object.send(:remove_const, :MyClass) rescue nil
18
+ end
19
+
20
+ def gemfile content
21
+ @gemfile = File.open(@instance.gemfile_path, 'w') {|f| f.write content }
22
+ end
23
+
24
+ it "should not be valid if the Gemfile does not exist" do
25
+ MyClass.validate :validate_gemfile_exists
26
+
27
+ @instance = MyClass.new
28
+ @instance.project_path = "tmp"
29
+
30
+ @instance.valid?
31
+ @instance.errors[:gem].should == ["file does not exist"]
32
+ end
33
+
34
+ describe "push_gem" do
35
+
36
+ def push *args
37
+ @instance.send :gem, *args
38
+ @gemfile = File.open(@instance.gemfile_path) {|f| f.read }
39
+ end
40
+
41
+ before do
42
+ FileUtils.mkdir_p 'tmp/test'
43
+ @instance = MyClass.new
44
+ @instance.project_path = 'tmp/test'
45
+
46
+ @instance.stub!(:pushing?).and_return(true)
47
+ @instance.stub!(:pulling?).and_return(false)
48
+ end
49
+
50
+ after do
51
+ FileUtils.rm_rf 'tmp/test'
52
+ end
53
+
54
+ it "should append the gem to the existing list" do
55
+ gemfile %(gem 'rails', '3.1.0')
56
+ push 'kaminari'
57
+ @gemfile.should == %(gem 'rails', '3.1.0'\ngem 'kaminari')
58
+ end
59
+
60
+ it "should push a version" do
61
+ gemfile %(gem 'rails', '3.1.0')
62
+ push 'kaminari', '1.0'
63
+ @gemfile.should == %(gem 'rails', '3.1.0'\ngem 'kaminari', '1.0')
64
+ end
65
+
66
+ it "should push options" do
67
+ gemfile %(gem 'rails', '3.1.0')
68
+ push 'kaminari', :git => 'git://somewhere'
69
+ @gemfile.should == %(gem 'rails', '3.1.0'\ngem 'kaminari', :git => "git://somewhere")
70
+ end
71
+
72
+ it "should not append the gem if it already exists" do
73
+ gemfile %(gem 'rails', '3.1.0')
74
+ push 'rails'
75
+ @gemfile.should == %(gem 'rails', '3.1.0')
76
+ end
77
+
78
+ it "should append to group block if available" do
79
+ gemfile %(gem 'rails', '3.1.0'\n\ngroup :development do\n gem 'capistrano'\nend)
80
+ push 'capistrano-ext', :group => 'development'
81
+ @gemfile.should == %(gem 'rails', '3.1.0'\n\ngroup :development do\n gem 'capistrano'\n gem 'capistrano-ext'\nend)
82
+ end
83
+
84
+ it "should append with group option if group does not exist" do
85
+ gemfile %(gem 'rails', '3.1.0')
86
+ push 'capistrano-ext', :group => 'development'
87
+ @gemfile.should == %(gem 'rails', '3.1.0'\ngem 'capistrano-ext', :group => :development)
88
+ end
89
+
90
+ it "should append to multiple groups block if available" do
91
+ gemfile %(gem 'rails', '3.1.0'\n\ngroup :development, :test do\n gem 'capistrano'\nend)
92
+ push 'capistrano-ext', :groups => ['development', 'test']
93
+ @gemfile.should == %(gem 'rails', '3.1.0'\n\ngroup :development, :test do\n gem 'capistrano'\n gem 'capistrano-ext'\nend)
94
+ end
95
+
96
+ it "should append with multiple groups option if group does not exist" do
97
+ gemfile %(gem 'rails', '3.1.0')
98
+ push 'capistrano-ext', :groups => ['development', 'test']
99
+ @gemfile.should == %(gem 'rails', '3.1.0'\ngem 'capistrano-ext', :groups => [:development, :test])
100
+ end
101
+
102
+ it "should push when :if is true" do
103
+ @instance.should_receive(:set?).with('foo').and_return(true)
104
+ gemfile %(gem 'rails', '3.1.0')
105
+
106
+ push 'capistrano-ext', :if => 'foo'
107
+ @gemfile.should == %(gem 'rails', '3.1.0'\ngem 'capistrano-ext')
108
+ end
109
+
110
+ it "should not push when :if is false" do
111
+ @instance.should_receive(:set?).with('foo').and_return(false)
112
+ gemfile %(gem 'rails', '3.1.0')
113
+
114
+ push 'capistrano-ext', :if => 'foo'
115
+ @gemfile.should == %(gem 'rails', '3.1.0')
116
+ end
117
+
118
+ end
119
+
120
+ describe "pull_gem" do
121
+
122
+ before do
123
+ FileUtils.mkdir_p 'tmp/test'
124
+ @instance = MyClass.new
125
+ @instance.project_path = 'tmp/test'
126
+
127
+ @instance.stub!(:pushing?).and_return(false)
128
+ @instance.stub!(:pulling?).and_return(true)
129
+ end
130
+
131
+ after do
132
+ FileUtils.rm_rf 'tmp/test'
133
+ end
134
+
135
+ it "should report an error it doesn't know where the Gemfile is" do
136
+ @instance.project_path = nil
137
+ @instance.should_receive(:error).with("kaminari", "Unknown Gemfile location")
138
+
139
+ @instance.send :gem, 'kaminari'
140
+ end
141
+
142
+ it "should report an error when the gemfile doesn't exist" do
143
+ @instance.should_receive(:error).with("kaminari", "Gemfile doesn't exist")
144
+
145
+ @instance.send :gem, 'kaminari'
146
+ end
147
+
148
+ it "should report an error when the gem isn't in the gem file" do
149
+ gemfile %()
150
+ @instance.should_receive(:error).with("kaminari", "isn't in your Gemfile")
151
+
152
+ @instance.send :gem, 'kaminari'
153
+ end
154
+
155
+ it "should report ok when the gem is in the gem file" do
156
+ gemfile %(gem 'kaminari')
157
+ @instance.should_receive(:ok).with("kaminari", "is in your Gemfile")
158
+
159
+ @instance.send :gem, 'kaminari'
160
+ end
161
+
162
+ it "should set the 'if' setting false" do
163
+ gemfile %()
164
+ @instance.should_receive(:ok).with('kaminari', "isn't in your Gemfile")
165
+ @instance.should_receive(:[]=).with('foo', false)
166
+
167
+ @instance.send :gem, 'kaminari', :if => 'foo'
168
+ end
169
+
170
+ it "should set the 'if' setting true" do
171
+ gemfile %(gem 'kaminari')
172
+ @instance.should_receive(:ok).with('kaminari', "is in your Gemfile")
173
+ @instance.should_receive(:[]=).with('foo', true)
174
+
175
+ @instance.send :gem, 'kaminari', :if => 'foo'
176
+ end
177
+
178
+ end
179
+
180
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe Rapid::Skeleton::Helpers::Migration do
4
+
5
+ before do
6
+ Object.class_eval do
7
+ class MyClass
8
+ include Rapid::Skeleton::Helpers::Template
9
+ include Rapid::Skeleton::Helpers::Migration
10
+
11
+ attr_accessor :templates_path, :project_path, :get_binding
12
+ end
13
+ end
14
+
15
+ @instance = MyClass.new
16
+ end
17
+
18
+ after do
19
+ Object.send(:remove_const, :MyClass) rescue nil
20
+ end
21
+
22
+
23
+ end
@@ -0,0 +1,120 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
2
+
3
+ describe Rapid::Skeleton::Helpers::Route do
4
+
5
+ before do
6
+ Object.class_eval do
7
+ class MyClass
8
+ include ActiveModel::Validations
9
+ include Rapid::Skeleton::Helpers::Route
10
+
11
+ attr_accessor :templates_path, :project_path, :get_binding
12
+ end
13
+ end
14
+ end
15
+
16
+ after do
17
+ Object.send(:remove_const, :MyClass) rescue nil
18
+ end
19
+
20
+ def routes content
21
+ @gemfile = File.open(@instance.routes_path, 'w') {|f| f.write content }
22
+ end
23
+
24
+ it "should not be valid if config/routes.rb does not exist" do
25
+ MyClass.validate :validate_routes_file_exists
26
+
27
+ @instance = MyClass.new
28
+ @instance.project_path = "tmp"
29
+
30
+ @instance.valid?
31
+ @instance.errors[:routes].should == ["file does not exist"]
32
+ end
33
+
34
+ describe "push_route" do
35
+
36
+ def push *args
37
+ @instance.send :route, *args
38
+ @routes = File.open(@instance.routes_path) {|f| f.read }
39
+ end
40
+
41
+ before do
42
+ FileUtils.mkdir_p 'tmp/test/config'
43
+ @instance = MyClass.new
44
+ @instance.project_path = 'tmp/test'
45
+
46
+ @instance.stub!(:pushing?).and_return(true)
47
+ @instance.stub!(:pulling?).and_return(false)
48
+ end
49
+
50
+ after do
51
+ FileUtils.rm_rf 'tmp/test'
52
+ end
53
+
54
+ it "should append the routes to the existing file" do
55
+ routes %(HelloWorld::Application.routes.draw do\nend)
56
+ push :get, 'sign-in', :to => 'user_sessions#new', :as => :sign_in
57
+ @routes.should == %(HelloWorld::Application.routes.draw do\n get 'sign-in', :to => 'user_sessions#new', :as => :sign_in\nend)
58
+ end
59
+
60
+ it "should not append the same route twice" do
61
+ routes %(HelloWorld::Application.routes.draw do\n get 'sign-in', :to => 'user_sessions#new', :as => :sign_in\nend)
62
+ push :get, 'sign-in', :to => 'user_sessions#new', :as => :sign_in
63
+ @routes.should == %(HelloWorld::Application.routes.draw do\n get 'sign-in', :to => 'user_sessions#new', :as => :sign_in\nend)
64
+ end
65
+
66
+ it "should append a route to a new namespace" do
67
+ routes %(HelloWorld::Application.routes.draw do\nend)
68
+ push :get, 'sign-in', :to => 'user_sessions#new', :as => :sign_in, :namespace => :admin
69
+ @routes.should == %(HelloWorld::Application.routes.draw do\n namespace :admin do\n get 'sign-in', :to => 'user_sessions#new', :as => :sign_in\n end\nend)
70
+ end
71
+
72
+ it "should append a route to an existing namespace" do
73
+ routes %(HelloWorld::Application.routes.draw do\n namespace :admin do\n get 'foo'\n end\nend)
74
+ push :get, 'sign-in', :to => 'user_sessions#new', :as => :sign_in, :namespace => :admin
75
+ @routes.should == %(HelloWorld::Application.routes.draw do\n namespace :admin do\n get 'foo'\n get 'sign-in', :to => 'user_sessions#new', :as => :sign_in\n end\nend)
76
+ end
77
+
78
+ end
79
+
80
+ describe "pull_route" do
81
+
82
+ before do
83
+ FileUtils.mkdir_p 'tmp/test/config'
84
+ @instance = MyClass.new
85
+ @instance.project_path = 'tmp/test'
86
+
87
+ @instance.stub!(:pushing?).and_return(false)
88
+ @instance.stub!(:pulling?).and_return(true)
89
+ end
90
+
91
+ it "should report an error when the project location is unknown" do
92
+ @instance.project_path = nil
93
+ @instance.should_receive(:error).with("config/routes.rb", "location is unknown")
94
+
95
+ @instance.send :route, :match, "/sign-in"
96
+ end
97
+
98
+ it "should report an error when the routes file does not exist" do
99
+ @instance.should_receive(:error).with("config/routes.rb", "doesn't exist")
100
+
101
+ @instance.send :route, :match, "/sign-in"
102
+ end
103
+
104
+ it "should report an error when the route does not exist" do
105
+ @instance.should_receive(:error).with(%(match '/sign-in'), "doesn't exist")
106
+ routes %()
107
+
108
+ @instance.send :route, :match, "/sign-in"
109
+ end
110
+
111
+ it "should report ok when the route exists" do
112
+ @instance.should_receive(:ok).with(%(match '/sign-in'), "exists")
113
+ routes %(HelloWorld::Application.routes.draw do\n match '/sign-in'\nend)
114
+
115
+ @instance.send :route, :match, "/sign-in"
116
+ end
117
+
118
+ end
119
+
120
+ end