rapid-core 0.1 → 0.2.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.
- data/.gitignore +1 -0
- data/Gemfile.lock +35 -2
- data/Rakefile +77 -48
- data/doc/server.txt +15 -0
- data/features/settings/double-nested/default.feature +2 -2
- data/features/settings/double-nested/validates/presence_of.feature +1 -1
- data/features/settings/nested/default.feature +1 -1
- data/features/settings/nested/validates/presence_of.feature +1 -1
- data/features/settings/not_found.feature +2 -2
- data/features/step_definitions/settings_steps.rb +7 -3
- data/features/step_definitions/template_steps.rb +3 -1
- data/lib/rapid/check.rb +30 -23
- data/lib/rapid/core.rb +12 -0
- data/lib/rapid/error.rb +1 -0
- data/lib/rapid/module.rb +10 -1
- data/lib/rapid/railtie.rb +6 -0
- data/lib/rapid/setting/base.rb +31 -8
- data/lib/rapid/setting/boolean_setting.rb +20 -1
- data/lib/rapid/setting/definer.rb +11 -47
- data/lib/rapid/setting/integer_setting.rb +7 -7
- data/lib/rapid/setting/module.rb +56 -0
- data/lib/rapid/setting/namespace/base.rb +35 -60
- data/lib/rapid/setting/namespace/instance.rb +195 -28
- data/lib/rapid/setting/string_setting.rb +7 -1
- data/lib/rapid/settings.rb +51 -65
- data/lib/rapid/skeleton/base.rb +39 -18
- data/lib/rapid/skeleton/helpers/directory.rb +5 -6
- data/lib/rapid/skeleton/helpers/files.rb +62 -0
- data/lib/rapid/skeleton/helpers/gem.rb +43 -32
- data/lib/rapid/skeleton/helpers/if_setting.rb +44 -0
- data/lib/rapid/skeleton/helpers/migration.rb +102 -32
- data/lib/rapid/skeleton/helpers/route.rb +8 -12
- data/lib/rapid/skeleton/helpers/script.rb +1 -2
- data/lib/rapid/skeleton/helpers/template.rb +23 -25
- data/lib/rapid/skeleton/helpers/view.rb +7 -7
- data/lib/rapid/spec/template.rb +1 -1
- data/lib/rapid/version.rb +1 -1
- data/lib/rapid/web/base.rb +35 -0
- data/lib/rapid/web/bootstrap.rb +98 -0
- data/lib/rapid/web/controller_helpers.rb +60 -0
- data/lib/rapid/web/navigator.rb +18 -0
- data/lib/rapid/web/select_helpers.rb +63 -0
- data/lib/rapid/web/settings_form_builder.rb +205 -0
- data/lib/rapid/web/static_helpers.rb +28 -0
- data/lib/rapid/web/tasks.rb +10 -0
- data/public/rapid/core/bootstrap-collapse.js +136 -0
- data/public/rapid/core/bootstrap-responsive.min.css +3 -0
- data/public/rapid/core/bootstrap.min.css +556 -0
- data/public/rapid/core/jquery-1.7.1.js +9253 -0
- data/public/rapid/core/prettify.css +30 -0
- data/public/rapid/core/prettify.js +28 -0
- data/rapid-core.gemspec +5 -0
- data/spec/rapid/check_spec.rb +11 -4
- data/spec/rapid/module_spec.rb +18 -0
- data/spec/rapid/setting/base_spec.rb +71 -0
- data/spec/rapid/setting/boolean_setting_spec.rb +95 -0
- data/spec/rapid/setting/definer_spec.rb +7 -13
- data/spec/rapid/setting/integer_setting_spec.rb +49 -0
- data/spec/rapid/setting/module_spec.rb +25 -0
- data/spec/rapid/setting/namespace/base_spec.rb +88 -54
- data/spec/rapid/setting/namespace/instance_spec.rb +308 -5
- data/spec/rapid/setting/string_setting_spec.rb +43 -0
- data/spec/rapid/settings_spec.rb +65 -17
- data/spec/rapid/skeleton/base_spec.rb +113 -7
- data/spec/rapid/skeleton/helpers/directory_spec.rb +8 -6
- data/spec/rapid/skeleton/helpers/files_spec.rb +93 -0
- data/spec/rapid/skeleton/helpers/gem_spec.rb +65 -36
- data/spec/rapid/skeleton/helpers/if_setting_spec.rb +110 -0
- data/spec/rapid/skeleton/helpers/migration_spec.rb +190 -1
- data/spec/rapid/skeleton/helpers/route_spec.rb +13 -12
- data/spec/rapid/skeleton/helpers/script_spec.rb +2 -1
- data/spec/rapid/skeleton/helpers/template_spec.rb +22 -35
- data/spec/rapid/spec/template_spec.rb +1 -1
- data/spec/rapid/web/base_spec.rb +33 -0
- data/spec/rapid/web/bootstrap_spec.rb +72 -0
- data/spec/rapid/web/controller_helpers_spec.rb +86 -0
- data/spec/rapid/web/navigator_spec.rb +17 -0
- data/spec/rapid/web/select_helpers_spec.rb +71 -0
- data/spec/rapid/web/settings_form_builder_spec.rb +255 -0
- data/spec/rapid/web/static_helpers_spec.rb +26 -0
- data/spec/spec_helper.rb +3 -0
- data/views/index.erb +11 -0
- data/views/layout.erb +9 -0
- metadata +107 -12
- data/lib/rapid.rb +0 -37
- data/lib/rapid/setting/class_hash.rb +0 -34
- data/lib/rapid/setting/instance_hash.rb +0 -132
- data/lib/rapid/setting/instance_root.rb +0 -107
- data/spec/rapid/setting/instance_root_spec.rb +0 -161
@@ -0,0 +1,110 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
|
2
|
+
|
3
|
+
describe Rapid::Skeleton::Helpers::IfSetting do
|
4
|
+
|
5
|
+
before do
|
6
|
+
Object.class_eval do
|
7
|
+
class MyClass
|
8
|
+
include Rapid::Skeleton::Helpers::IfSetting
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
@instance = MyClass.new
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
Object.send(:remove_const, :MyClass) rescue nil
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "has_if_setting?" do
|
20
|
+
|
21
|
+
def has_if_setting? options
|
22
|
+
@instance.send(:has_if_setting?, options)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be true if the options contain an if statement" do
|
26
|
+
has_if_setting?(:if => 'foo').should == true
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should be false if the options don't contain an if statement" do
|
30
|
+
has_if_setting?(:foo => true).should == false
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "if_setting_off?" do
|
36
|
+
|
37
|
+
def if_setting_off? options
|
38
|
+
@instance.send(:if_setting_off?, options)
|
39
|
+
end
|
40
|
+
|
41
|
+
def set? setting, bool
|
42
|
+
@instance.should_receive(:set?).with(setting).and_return(bool)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should be true when :if => setting exists and not set" do
|
46
|
+
set? 'foo', false
|
47
|
+
if_setting_off?(:if => 'foo').should == true
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should be false when :if => setting does not exist" do
|
51
|
+
if_setting_off?({}).should == false
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should be false when :if => setting exists and set" do
|
55
|
+
set? 'foo', true
|
56
|
+
if_setting_off?(:if => 'foo').should == false
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should be true when :if => [setting1, setting2] are all not set" do
|
60
|
+
set? 'foo', true
|
61
|
+
set? 'bar', true
|
62
|
+
if_setting_off?(:if => ['foo', 'bar']).should == false
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should be false when :if => [setting1, setting2] are not all set" do
|
66
|
+
set? 'foo', true
|
67
|
+
set? 'bar', false
|
68
|
+
if_setting_off?(:if => ['foo', 'bar']).should == true
|
69
|
+
|
70
|
+
set? 'foo', false
|
71
|
+
# set? 'bar', true # short-circuited
|
72
|
+
if_setting_off?(:if => ['foo', 'bar']).should == true
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "if_set!" do
|
78
|
+
|
79
|
+
def if_set! bool, options
|
80
|
+
@instance.send(:if_set!, bool, options)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should set :if => setting to true" do
|
84
|
+
@instance.should_receive(:[]=).with('foo', true)
|
85
|
+
if_set! true, :if => 'foo'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should set :if => setting to false" do
|
89
|
+
@instance.should_receive(:[]=).with('foo', false)
|
90
|
+
if_set! false, :if => 'foo'
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should set :if => [setting1, setting2] to true" do
|
94
|
+
@instance.should_receive(:[]).with('foo')
|
95
|
+
@instance.should_receive(:[]).with('bar')
|
96
|
+
@instance.should_receive(:[]=).with('foo', true)
|
97
|
+
@instance.should_receive(:[]=).with('bar', true)
|
98
|
+
if_set! true, :if => ['foo', 'bar']
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should not set :if => [setting1, setting2] if it's already set" do
|
102
|
+
@instance.should_receive(:[]).with('foo')
|
103
|
+
@instance.should_receive(:[]).with('bar').and_return(true)
|
104
|
+
@instance.should_receive(:[]=).with('foo', true)
|
105
|
+
if_set! true, :if => ['foo', 'bar']
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -5,7 +5,7 @@ describe Rapid::Skeleton::Helpers::Migration do
|
|
5
5
|
before do
|
6
6
|
Object.class_eval do
|
7
7
|
class MyClass
|
8
|
-
include Rapid::Skeleton::Helpers::
|
8
|
+
include Rapid::Skeleton::Helpers::IfSetting
|
9
9
|
include Rapid::Skeleton::Helpers::Migration
|
10
10
|
|
11
11
|
attr_accessor :templates_path, :project_path, :get_binding
|
@@ -13,10 +13,199 @@ describe Rapid::Skeleton::Helpers::Migration do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
@instance = MyClass.new
|
16
|
+
@instance.project_path = "tmp/test/project"
|
17
|
+
@instance.templates_path = "tmp/test/templates"
|
18
|
+
|
19
|
+
FileUtils.mkdir_p File.join(@instance.project_path, 'db', 'migrate')
|
20
|
+
FileUtils.mkdir_p File.join(@instance.templates_path, 'db', 'migrate')
|
21
|
+
|
22
|
+
@time = Time.parse("Mon Feb 20 17:12:34 -0500 2012")
|
23
|
+
Time.stub!(:now).and_return(@time)
|
16
24
|
end
|
17
25
|
|
18
26
|
after do
|
19
27
|
Object.send(:remove_const, :MyClass) rescue nil
|
28
|
+
FileUtils.rm_rf "tmp/test"
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_file name, content
|
32
|
+
File.open(name, 'w') {|f| f.write content }
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_project_migration name, content
|
36
|
+
path = File.join 'tmp', 'test', 'project', 'db', 'migrate', name
|
37
|
+
create_file path, content
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_template_migration name, content
|
41
|
+
path = File.join 'tmp', 'test', 'templates', 'db', 'migrate', name
|
42
|
+
create_file path, content
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should progressively create timestamped migrations" do
|
46
|
+
@instance.send(:timestamped_migration, 'create_users.rb').should == "20120220221234_create_users.rb"
|
47
|
+
@instance.send(:timestamped_migration, '02_create_groups.rb').should == "20120220221235_create_groups.rb"
|
48
|
+
@instance.send(:timestamped_migration, '02_create_accounts.rb').should == "20120220221236_create_accounts.rb"
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "pull" do
|
52
|
+
|
53
|
+
before do
|
54
|
+
@instance.stub!(:pushing?).and_return(false)
|
55
|
+
@instance.stub!(:pulling?).and_return(true)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should pull the template's timestamped name" do
|
59
|
+
@instance.should_receive(:find_project_migration).with('create_users').and_return("01_create_users.rb")
|
60
|
+
@instance.should_receive(:pull_template).with("db/migrate/create_users.rb", :to => "db/migrate/01_create_users.rb")
|
61
|
+
|
62
|
+
@instance.send(:migration, "create_users")
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should should set :if to true when the template exists" do
|
66
|
+
@instance.should_receive(:find_project_migration).with('create_users').and_return("01_create_users.rb")
|
67
|
+
@instance.should_receive(:pull_template).with("db/migrate/create_users.rb", :to => "db/migrate/01_create_users.rb")
|
68
|
+
@instance.should_receive(:[]=).with('foo', true)
|
69
|
+
|
70
|
+
@instance.send(:migration, "create_users", :if => 'foo')
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should should set :if to false when the template does not exist" do
|
74
|
+
@instance.should_receive(:find_project_migration).with('create_users').and_return(nil)
|
75
|
+
@instance.should_receive(:[]=).with('foo', false)
|
76
|
+
|
77
|
+
@instance.send(:migration, "create_users", :if => 'foo')
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "push" do
|
83
|
+
|
84
|
+
before do
|
85
|
+
@instance.stub!(:pushing?).and_return(true)
|
86
|
+
@instance.stub!(:pulling?).and_return(false)
|
87
|
+
end
|
88
|
+
|
89
|
+
def push name, options = {}
|
90
|
+
@instance.send :migration, name, options
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should create the migration file" do
|
94
|
+
@instance.should_receive(:push_template).with('db/migrate/create_users.rb', :to => "db/migrate/20120220221234_create_users.rb")
|
95
|
+
push 'create_users'
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should create the migration file when the if setting is true" do
|
99
|
+
@instance.should_receive(:set?).with('foo').and_return(true)
|
100
|
+
@instance.should_receive(:push_template).with('db/migrate/create_users.rb', :to => "db/migrate/20120220221234_create_users.rb")
|
101
|
+
push 'create_users', :if => 'foo'
|
102
|
+
end
|
103
|
+
|
104
|
+
describe ":if => false" do
|
105
|
+
|
106
|
+
before do
|
107
|
+
@instance.should_receive(:set?).with('foo').and_return(false)
|
108
|
+
@instance.should_receive(:find_project_migration).with('create_users').and_return("01_create_users.rb")
|
109
|
+
end
|
110
|
+
|
111
|
+
def in_version_control! bool
|
112
|
+
@instance.should_receive(:in_version_control?).with("db/migrate/01_create_users.rb").and_return(bool)
|
113
|
+
end
|
114
|
+
|
115
|
+
def in_schema! bool
|
116
|
+
@instance.should_receive(:in_local_schema?).with("db/migrate/01_create_users.rb").and_return(bool)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should do nothing when it's in version control but not in the schema" do
|
120
|
+
in_version_control! true
|
121
|
+
in_schema! false
|
122
|
+
|
123
|
+
push 'create_users', :if => 'foo'
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should create a reverse migration when it's in version control and the schema" do
|
127
|
+
@instance.should_receive(:reverse_migration).with("01_create_users.rb", {})
|
128
|
+
|
129
|
+
in_version_control! true
|
130
|
+
in_schema! true
|
131
|
+
|
132
|
+
push 'create_users', :if => 'foo'
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should delete the migration file when it's not in version control or the local schema" do
|
136
|
+
@instance.should_receive(:delete_project_file).with("db/migrate/01_create_users.rb")
|
137
|
+
|
138
|
+
in_version_control! false
|
139
|
+
in_schema! false
|
140
|
+
|
141
|
+
push 'create_users', :if => 'foo'
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should report an error when it's not in version control but is in the schema" do
|
145
|
+
@instance.should_receive(:error).with("create_users", "must be rolled back before removing")
|
146
|
+
|
147
|
+
in_version_control! false
|
148
|
+
in_schema! true
|
149
|
+
|
150
|
+
push 'create_users', :if => 'foo'
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "in_local_schema?" do
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "reverse_migration" do
|
164
|
+
|
165
|
+
before do
|
166
|
+
|
167
|
+
@create_users_code = %(class CreateUsers < ActiveRecord::Migration
|
168
|
+
def self.up
|
169
|
+
|
170
|
+
create_table "users", :force => true do |t|
|
171
|
+
t.string "email"
|
172
|
+
t.datetime "created_at"
|
173
|
+
t.datetime "updated_at"
|
174
|
+
end
|
175
|
+
|
176
|
+
end
|
177
|
+
|
178
|
+
def self.down
|
179
|
+
drop_table :users
|
180
|
+
end
|
181
|
+
end
|
182
|
+
)
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
end
|
187
|
+
|
188
|
+
describe "find_project_migration" do
|
189
|
+
|
190
|
+
def find name
|
191
|
+
@instance.send(:find_project_migration, name)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should find the name with timestamps" do
|
195
|
+
create_project_migration "01_create_users.rb", "hi"
|
196
|
+
find("create_users").should == "01_create_users"
|
197
|
+
end
|
198
|
+
|
199
|
+
it "should find the name without timestamps" do
|
200
|
+
create_project_migration "create_users.rb", "hi"
|
201
|
+
find("create_users").should == "create_users"
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should not find the name if it's not there" do
|
205
|
+
create_project_migration "01_create_accounts.rb", "hi"
|
206
|
+
find("create_users").should == nil
|
207
|
+
end
|
208
|
+
|
20
209
|
end
|
21
210
|
|
22
211
|
|
@@ -18,7 +18,8 @@ describe Rapid::Skeleton::Helpers::Route do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def routes content
|
21
|
-
@
|
21
|
+
@instance.stub!(:project_file_exists?).with('config/routes.rb').and_return(true)
|
22
|
+
@instance.stub!(:read_project_file).with('config/routes.rb').and_return(content)
|
22
23
|
end
|
23
24
|
|
24
25
|
it "should not be valid if config/routes.rb does not exist" do
|
@@ -26,6 +27,7 @@ describe Rapid::Skeleton::Helpers::Route do
|
|
26
27
|
|
27
28
|
@instance = MyClass.new
|
28
29
|
@instance.project_path = "tmp"
|
30
|
+
@instance.should_receive(:project_file_exists?).with('config/routes.rb').and_return(false)
|
29
31
|
|
30
32
|
@instance.valid?
|
31
33
|
@instance.errors[:routes].should == ["file does not exist"]
|
@@ -35,44 +37,42 @@ describe Rapid::Skeleton::Helpers::Route do
|
|
35
37
|
|
36
38
|
def push *args
|
37
39
|
@instance.send :route, *args
|
38
|
-
@routes = File.open(@instance.routes_path) {|f| f.read }
|
39
40
|
end
|
40
41
|
|
41
42
|
before do
|
42
|
-
FileUtils.mkdir_p 'tmp/test/config'
|
43
43
|
@instance = MyClass.new
|
44
|
-
@instance.project_path = 'tmp
|
44
|
+
@instance.project_path = 'tmp'
|
45
45
|
|
46
46
|
@instance.stub!(:pushing?).and_return(true)
|
47
47
|
@instance.stub!(:pulling?).and_return(false)
|
48
48
|
end
|
49
49
|
|
50
|
-
after do
|
51
|
-
FileUtils.rm_rf 'tmp/test'
|
52
|
-
end
|
53
|
-
|
54
50
|
it "should append the routes to the existing file" do
|
51
|
+
@instance.should_receive(:write_project_file).with('config/routes.rb', %(HelloWorld::Application.routes.draw do\n get 'sign-in', :to => 'user_sessions#new', :as => :sign_in\nend))
|
52
|
+
|
55
53
|
routes %(HelloWorld::Application.routes.draw do\nend)
|
56
54
|
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
55
|
end
|
59
56
|
|
60
57
|
it "should not append the same route twice" do
|
58
|
+
@instance.should_receive(:write_project_file).with('config/routes.rb', %(HelloWorld::Application.routes.draw do\n get 'sign-in', :to => 'user_sessions#new', :as => :sign_in\nend))
|
59
|
+
|
61
60
|
routes %(HelloWorld::Application.routes.draw do\n get 'sign-in', :to => 'user_sessions#new', :as => :sign_in\nend)
|
62
61
|
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
62
|
end
|
65
63
|
|
66
64
|
it "should append a route to a new namespace" do
|
65
|
+
@instance.should_receive(:write_project_file).with('config/routes.rb', %(HelloWorld::Application.routes.draw do\n namespace :admin do\n get 'sign-in', :to => 'user_sessions#new', :as => :sign_in\n end\nend))
|
66
|
+
|
67
67
|
routes %(HelloWorld::Application.routes.draw do\nend)
|
68
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
69
|
end
|
71
70
|
|
72
71
|
it "should append a route to an existing namespace" do
|
72
|
+
@instance.should_receive(:write_project_file).with('config/routes.rb', %(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))
|
73
|
+
|
73
74
|
routes %(HelloWorld::Application.routes.draw do\n namespace :admin do\n get 'foo'\n end\nend)
|
74
75
|
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
76
|
end
|
77
77
|
|
78
78
|
end
|
@@ -96,6 +96,7 @@ describe Rapid::Skeleton::Helpers::Route do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
it "should report an error when the routes file does not exist" do
|
99
|
+
@instance.should_receive(:project_file_exists?).with('config/routes.rb').and_return(false)
|
99
100
|
@instance.should_receive(:error).with("config/routes.rb", "doesn't exist")
|
100
101
|
|
101
102
|
@instance.send :route, :match, "/sign-in"
|
@@ -30,7 +30,8 @@ describe Rapid::Skeleton::Helpers::Script do
|
|
30
30
|
|
31
31
|
it "should push_template and chmod it executable" do
|
32
32
|
@instance.should_receive(:push_template).with("script/test", {})
|
33
|
-
|
33
|
+
@instance.should_receive(:project_file_exists?).with('script/test').and_return(true)
|
34
|
+
@instance.should_receive(:chmod_project_file).with(0755, 'script/test')
|
34
35
|
|
35
36
|
@instance.send :script, "script/test"
|
36
37
|
end
|
@@ -5,38 +5,29 @@ describe Rapid::Skeleton::Helpers::Template do
|
|
5
5
|
before do
|
6
6
|
Object.class_eval do
|
7
7
|
class MyClass
|
8
|
+
include Rapid::Skeleton::Helpers::IfSetting
|
8
9
|
include Rapid::Skeleton::Helpers::Template
|
9
10
|
|
10
11
|
attr_accessor :templates_path, :project_path, :get_binding
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
|
-
@test_path = File.join 'tmp', 'test'
|
15
|
-
@templates_path = File.join @test_path, 'templates'
|
16
|
-
@project_path = File.join @test_path, 'project'
|
17
|
-
|
18
15
|
@instance = MyClass.new
|
19
|
-
@instance.templates_path =
|
20
|
-
@instance.project_path =
|
16
|
+
@instance.templates_path = 'templates'
|
17
|
+
@instance.project_path = 'project'
|
21
18
|
end
|
22
19
|
|
23
20
|
after do
|
24
21
|
Object.send(:remove_const, :MyClass) rescue nil
|
25
|
-
FileUtils.rm_rf @test_path
|
26
22
|
end
|
27
23
|
|
28
24
|
def create_template filename, content
|
29
|
-
|
30
|
-
|
31
|
-
FileUtils.mkdir_p File.dirname(template_path)
|
32
|
-
File.open(template_path, 'w') {|f| f.write content }
|
25
|
+
@instance.stub!(:read_template_file).with(filename).and_return(content)
|
33
26
|
end
|
34
27
|
|
35
28
|
def create_output filename, content
|
36
|
-
|
37
|
-
|
38
|
-
FileUtils.mkdir_p File.dirname(output_path)
|
39
|
-
File.open(output_path, 'w') {|f| f.write content }
|
29
|
+
@instance.stub!(:project_file_exists?).with(filename).and_return(true)
|
30
|
+
@instance.stub!(:read_project_file).with(filename).and_return(content)
|
40
31
|
end
|
41
32
|
|
42
33
|
describe "push_template" do
|
@@ -47,42 +38,33 @@ describe Rapid::Skeleton::Helpers::Template do
|
|
47
38
|
end
|
48
39
|
|
49
40
|
it "should render the template and write it to the given file" do
|
41
|
+
@instance.should_receive(:write_project_file).with('db/migrate/20120202030406_create_users.rb', 'foo 3 bar')
|
42
|
+
|
50
43
|
create_template 'db/migrate/01_create_users.rb', 'foo <%= 3 %> bar'
|
51
44
|
@instance.send :template, "db/migrate/01_create_users.rb", :to => "db/migrate/20120202030406_create_users.rb"
|
52
|
-
|
53
|
-
output_path = File.join @project_path, "db/migrate/20120202030406_create_users.rb"
|
54
|
-
File.open(output_path) {|f| f.read }.should == "foo 3 bar"
|
55
45
|
end
|
56
46
|
|
57
47
|
it "should write the rendered template to the template path if :to option is not given" do
|
48
|
+
@instance.should_receive(:write_project_file).with('config/initializers/airbrake.rb', 'foo 3 bar')
|
49
|
+
|
58
50
|
create_template 'config/initializers/airbrake.rb', 'foo <%= 3 %> bar'
|
59
51
|
@instance.send :template, "config/initializers/airbrake.rb"
|
60
|
-
|
61
|
-
output_path = File.join @project_path, "config/initializers/airbrake.rb"
|
62
|
-
File.open(output_path) {|f| f.read }.should == "foo 3 bar"
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should raise a template not found error when told to push an non-existing template" do
|
66
|
-
lambda { @instance.send :template, "db/migrate/01_create_users.rb", :to => "db/migrate/20120202030406_create_users.rb" }.should raise_error(Rapid::TemplateNotFoundError)
|
67
52
|
end
|
68
53
|
|
69
54
|
it "should push when :if is true" do
|
55
|
+
@instance.should_receive(:write_project_file).with('foo.rb', 'hi')
|
56
|
+
|
70
57
|
create_template 'foo.rb', 'hi'
|
71
58
|
@instance.should_receive(:set?).with('foo').and_return(true)
|
72
59
|
|
73
60
|
@instance.send :template, "foo.rb", :if => 'foo'
|
74
|
-
|
75
|
-
output_path = File.join @project_path, "foo.rb"
|
76
|
-
File.open(output_path) {|f| f.read }.should == "hi"
|
77
61
|
end
|
78
62
|
|
79
|
-
it "should
|
63
|
+
it "should delete the template when :if is false" do
|
80
64
|
@instance.should_receive(:set?).with('foo').and_return(false)
|
65
|
+
@instance.should_receive(:delete_project_file).with('foo.rb')
|
81
66
|
|
82
67
|
@instance.send :template, "foo.rb", :if => 'foo'
|
83
|
-
|
84
|
-
output_path = File.join @project_path, "foo.rb"
|
85
|
-
File.exists?(output_path).should == false
|
86
68
|
end
|
87
69
|
|
88
70
|
end
|
@@ -95,9 +77,11 @@ describe Rapid::Skeleton::Helpers::Template do
|
|
95
77
|
end
|
96
78
|
|
97
79
|
it "should report an error when the template does not exist" do
|
98
|
-
|
80
|
+
@instance.should_receive(:project_file_exists?).with('config/initializers/airbrake.rb').and_return(false)
|
99
81
|
@instance.should_receive(:error).with("config/initializers/airbrake.rb", "doesn't exist")
|
100
82
|
|
83
|
+
create_template 'config/initializers/airbrake.rb', 'foo <%= 3 %> bar'
|
84
|
+
|
101
85
|
@instance.send :template, "config/initializers/airbrake.rb"
|
102
86
|
end
|
103
87
|
|
@@ -115,15 +99,17 @@ describe Rapid::Skeleton::Helpers::Template do
|
|
115
99
|
create_output 'config/initializers/airbrake.rb', 'foo Dan bar'
|
116
100
|
|
117
101
|
@instance.should_receive(:ok).with("config/initializers/airbrake.rb", "is good")
|
102
|
+
@instance.should_receive(:[]=).with("name", "Dan")
|
118
103
|
|
119
104
|
@instance.send :template, "config/initializers/airbrake.rb"
|
120
105
|
end
|
121
106
|
|
122
107
|
it "should set the 'if' setting false if the project file is missing" do
|
123
|
-
|
124
|
-
|
108
|
+
@instance.should_receive(:project_file_exists?).with('foo.rb').and_return(false)
|
125
109
|
@instance.should_receive(:[]=).with('foo', false)
|
126
110
|
|
111
|
+
create_template 'foo.rb', 'foo <%= name %> bar'
|
112
|
+
|
127
113
|
@instance.send :template, 'foo.rb', :if => 'foo'
|
128
114
|
end
|
129
115
|
|
@@ -132,6 +118,7 @@ describe Rapid::Skeleton::Helpers::Template do
|
|
132
118
|
create_output 'foo.rb', 'foo Dan bar'
|
133
119
|
|
134
120
|
@instance.should_receive(:ok)
|
121
|
+
@instance.should_receive(:[]=).with('name', "Dan")
|
135
122
|
@instance.should_receive(:[]=).with('foo', true)
|
136
123
|
|
137
124
|
@instance.send :template, 'foo.rb', :if => 'foo'
|