blueprints 0.7.3 → 0.8.0

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.
@@ -91,37 +91,19 @@ describe Blueprints do
91
91
  end
92
92
 
93
93
  it "should clear scenarios when calling demolish" do
94
- demolish
95
- Fruit.count.should == 0
96
- end
97
-
98
- it "should clear only tables passed" do
99
- Tree.create!(:name => 'oak')
100
- demolish :fruits
101
- Tree.count.should == 1
102
- Fruit.count.should == 0
103
- end
104
-
105
- it "should mark scenarios as undone when passed :undone option" do
106
- build :fruit
107
- demolish :undo => [:apple]
108
- Fruit.count.should == 0
94
+ demolish :apple
95
+ Fruit.all.should_not include(@apple)
109
96
  build :apple
110
- Fruit.count.should == 1
97
+ Fruit.last.should == @apple
111
98
  end
112
99
 
113
- it "should mark all scenarios as undone when passed :undone option as :all" do
114
- build :fruit
115
- demolish :undo => :all
116
- Fruit.count.should == 0
117
- build :fruit
118
- Fruit.count.should == 2
119
- end
100
+ it "should overwrite auto created instance variable with another auto created one" do
101
+ build :acorn => {:average_diameter => 3}
102
+ demolish :acorn
103
+ @acorn.average_diameter.should == 3
120
104
 
121
- it "should raise error when not executed scenarios passed to :undo option" do
122
- lambda {
123
- demolish :undo => :orange
124
- }.should raise_error(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'orange'")
105
+ build :acorn => {:average_diameter => 5}
106
+ @acorn.average_diameter.should == 5
125
107
  end
126
108
  end
127
109
 
@@ -167,13 +149,13 @@ describe Blueprints do
167
149
  it 'should raise ScenarioNotFoundError when scenario could not be found' do
168
150
  lambda {
169
151
  build :not_existing
170
- }.should raise_error(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'not_existing'")
152
+ }.should raise_error(Blueprints::BlueprintNotFoundError)
171
153
  end
172
154
 
173
155
  it 'should raise ScenarioNotFoundError when scenario parent could not be found' do
174
156
  lambda {
175
157
  build :parent_not_existing
176
- }.should raise_error(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'not_existing'")
158
+ }.should raise_error(Blueprints::BlueprintNotFoundError)
177
159
  end
178
160
 
179
161
  it 'should raise TypeError when scenario name is not symbol or string' do
@@ -314,15 +296,6 @@ describe Blueprints do
314
296
  end
315
297
  end
316
298
 
317
- it "should overwrite auto created instance variable with another auto created one" do
318
- build :acorn => {:average_diameter => 3}
319
- demolish :fruits, :undo => :acorn
320
- @acorn.average_diameter.should == 3
321
-
322
- build :acorn => {:average_diameter => 5}
323
- @acorn.average_diameter.should == 5
324
- end
325
-
326
299
  describe "extending blueprints" do
327
300
  it "should allow to call build method inside blueprint body" do
328
301
  build :small_acorn
@@ -364,12 +337,6 @@ describe Blueprints do
364
337
  Blueprints::Blueprint.new(:overwritten, __FILE__)
365
338
  end
366
339
 
367
- it "should warn when building with options and blueprint is already built" do
368
- STDERR.expects(:puts).with("**WARNING** Building with options, but blueprint was already built: 'big_cherry'")
369
- STDERR.expects(:puts).with(regexp_matches(/blueprints_(spec|test)\.rb:\d+/))
370
- build :big_cherry => {:species => 'some species'}
371
- end
372
-
373
340
  describe 'attributes' do
374
341
  it "should allow to extract attributes from blueprint" do
375
342
  build_attributes('attributes.cherry').should == {:species => 'cherry'}
@@ -394,14 +361,14 @@ describe Blueprints do
394
361
 
395
362
  it "should return build attributes for dependencies" do
396
363
  attrs = build_attributes('attributes.dependent_cherry1')
397
- @pine.should_not be_nil
398
- attrs[:tree].should == @pine
364
+ @the_pine.should_not be_nil
365
+ attrs[:tree].should == @the_pine
399
366
  end
400
367
 
401
368
  it "should return build attributes for :@var" do
402
369
  attrs = build_attributes('attributes.dependent_cherry2')
403
- @pine.should_not be_nil
404
- attrs[:tree].should == @pine
370
+ @the_pine.should_not be_nil
371
+ attrs[:tree].should == @the_pine
405
372
  end
406
373
  end
407
374
 
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'fileutils'
3
2
  require 'logger'
4
3
  version = ENV['RAILS']
@@ -4,4 +4,6 @@ end
4
4
 
5
5
  blueprint :big_cherry do
6
6
  Fruit.new('cherry', 10)
7
- end
7
+ end
8
+
9
+ Fruit.blueprint :apple, :species => 'apple', :size => 3
@@ -23,4 +23,23 @@ describe Blueprints do
23
23
  @big_cherry.size = 13
24
24
  end
25
25
  end
26
- end
26
+
27
+ describe "build per describe" do
28
+ build_blueprint :cherry
29
+
30
+ it "should have cherry" do
31
+ @cherry.should_not be_nil
32
+ end
33
+
34
+ it "should have correct cherry species" do
35
+ @cherry.species.should == 'cherry'
36
+ end
37
+ end
38
+
39
+ it "should allow shortened forms of blueprint for any type of object" do
40
+ build :apple
41
+ @apple.should_not be_nil
42
+ @apple.species.should == 'apple'
43
+ @apple.size.should == 3
44
+ end
45
+ end
@@ -1,8 +1,15 @@
1
1
  class Fruit
2
2
  attr_accessor :species, :size
3
+ include Blueprints::Blueprintable
3
4
 
4
5
  def initialize(species, size = 5)
5
6
  @species = species
6
7
  @size = size
7
8
  end
9
+
10
+ private
11
+
12
+ def self.blueprint_object(attrs)
13
+ new(attrs[:species], attrs[:size])
14
+ end
8
15
  end
@@ -11,5 +11,4 @@ end
11
11
  Blueprints.enable do |config|
12
12
  config.root = File.expand_path(File.join(File.dirname(__FILE__)))
13
13
  config.prebuild = :big_cherry
14
- config.orm = nil
15
14
  end
data/spec/test_all.sh CHANGED
@@ -6,6 +6,8 @@ function e {
6
6
  echo '----------------------------------------'
7
7
  }
8
8
 
9
+ [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
10
+
9
11
  e "Normal spec"
10
12
  spec spec/active_record/blueprints_spec.rb
11
13
 
@@ -16,6 +18,7 @@ e "With no db"
16
18
  spec spec/no_db/blueprints_spec.rb
17
19
 
18
20
  e "With Test::Unit"
21
+ rake rspec_to_test
19
22
  ruby test/blueprints_test.rb
20
23
 
21
24
  e "With Cucumber"
@@ -26,11 +29,11 @@ rvm 1.8.7
26
29
  RAILS=3 rspec spec/active_record/blueprints_spec.rb
27
30
 
28
31
  e "With ruby 1.9.1"
29
- rvm use 1.9.1
32
+ rvm 1.9.1
30
33
  spec spec/active_record/blueprints_spec.rb
31
34
 
32
35
  e "With ruby 1.8.6"
33
- rvm use 1.8.6
36
+ rvm 1.8.6
34
37
  spec spec/active_record/blueprints_spec.rb
35
38
 
36
- rvm use system
39
+ rvm system
@@ -0,0 +1,17 @@
1
+ require 'active_record'
2
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
+ require 'spec/active_record/fixtures/fruit'
4
+ require 'spec/active_record/fixtures/tree'
5
+
6
+ databases = YAML::load(IO.read("spec/active_record/fixtures/database.yml"))
7
+ db_info = databases[ENV["DB"] || "test"]
8
+ ActiveRecord::Base.establish_connection(db_info)
9
+
10
+ describe ActiveRecord::Base do
11
+ it "should allow calling blueprint on associations" do
12
+ tree = Tree.blueprint(:name => 'tree')
13
+ fruit = tree.fruits.blueprint(:species => 'fruit')
14
+ fruit.should be_instance_of(Fruit)
15
+ fruit.species.should == 'fruit'
16
+ end
17
+ end
@@ -0,0 +1,58 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Blueprints::Blueprint do
4
+ before do
5
+ mock = @mock
6
+ @blueprint = Blueprints::Blueprint.new(:blueprint, __FILE__) { mock }
7
+ Blueprints::Namespace.root.build :blueprint
8
+ end
9
+
10
+ describe "demolish" do
11
+ before do
12
+ @mock.stubs(:destroy)
13
+ end
14
+
15
+ it "should allow to demolish blueprint" do
16
+ @mock.expects(:destroy)
17
+ @blueprint.demolish
18
+ end
19
+
20
+ it "should unset @result after demolish" do
21
+ @blueprint.demolish
22
+ @blueprint.instance_variable_defined?(:@result).should be_false
23
+ end
24
+
25
+ it "should raise error if @result is not set" do
26
+ @blueprint.demolish
27
+ lambda { @blueprint.demolish }.should raise_error(Blueprints::DemolishError)
28
+ end
29
+
30
+ it "should set blueprint as not built" do
31
+ @blueprint.demolish
32
+ Blueprints::Namespace.root.executed_blueprints.should_not include(@blueprint)
33
+ end
34
+
35
+ it "should allow to customize demolishing" do
36
+ @mock.expects(:demolish)
37
+ @blueprint.demolish { @blueprint.demolish }
38
+ @blueprint.demolish
39
+ end
40
+ end
41
+
42
+ describe "updating" do
43
+ it "should allow building blueprint with different parameters" do
44
+ @mock.expects(:blueprint).with(:option => 'value')
45
+ Blueprints::RootNamespace.root.build(:blueprint => {:option => 'value'})
46
+ end
47
+
48
+ it "should allow customizing update block" do
49
+ @blueprint.update { @blueprint.update_attributes(options) }
50
+ @mock.expects(:update_attributes).with(:option => 'value')
51
+ Blueprints::RootNamespace.root.build(:blueprint => {:option => 'value'})
52
+ end
53
+
54
+ it "should not update if build_once is false" do
55
+ Blueprints::RootNamespace.root.build({:blueprint => {:option => 'value'}}, nil, false)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Blueprints::Buildable do
4
+ before do
5
+ mock = @mock
6
+ @blueprint = Blueprints::Blueprint.new(:blueprint, __FILE__) { mock }
7
+ end
8
+
9
+ describe "normalize attributes" do
10
+ it "should allow passing dependent normalize Blueprints::Dependency object" do
11
+ Blueprints::Buildable.normalize_attributes(:name => Blueprints::Dependency.new(:blueprint)).should == {:name => @mock}
12
+ end
13
+ end
14
+ end
@@ -11,8 +11,7 @@ describe Blueprints::Configuration do
11
11
  end
12
12
  end
13
13
 
14
- it "should have correct attribute values" do
15
- @config.orm.should == :active_record
14
+ it "should have correct attribute values" do\
16
15
  @config.prebuild.should == []
17
16
  @config.transactions.should be_true
18
17
  @config.root.should == Pathname.pwd
@@ -28,16 +27,6 @@ describe Blueprints::Configuration do
28
27
  Object.send(:remove_const, :Rails)
29
28
  end
30
29
 
31
- it "should allow to set only supported orm" do
32
- Blueprints::Configuration::SUPPORTED_ORMS.should == [nil, :active_record]
33
- @config.orm = nil
34
- @config.orm.should be_nil
35
-
36
- lambda {
37
- @config.orm = :not_existing
38
- }.should raise_error(ArgumentError, 'Unsupported ORM :not_existing. Blueprints supports only nil, :active_record')
39
- end
40
-
41
30
  it "should set root to pathname" do
42
31
  @config.root = "root"
43
32
  @config.root.should == Pathname.new("root")
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Blueprints::Dependency do
4
+ before do
5
+ Blueprints::RootNamespace.root.context.instance_eval do
6
+ @value = :value
7
+ end
8
+
9
+ mock = @mock
10
+ @value = value = Mocha::Mockery.instance.unnamed_mock
11
+ @blueprint = Blueprints::Blueprint.new(:blueprint, __FILE__) do
12
+ @value = value
13
+ options.present? ? options : mock
14
+ end
15
+ end
16
+
17
+ it "should allow getting instance variable value" do
18
+ Blueprints::Dependency.new(:blueprint).value.should == @mock
19
+ end
20
+
21
+ it "should allow getting another instance variable" do
22
+ Blueprints::Dependency.new(:blueprint, :value).value.should == @value
23
+ end
24
+
25
+ it "should allow passing options for building" do
26
+ Blueprints::Dependency.new(:blueprint, :option => 'value').value.should == {:option => 'value'}
27
+ end
28
+
29
+ it "should record all missing methods" do
30
+ dependency = Blueprints::Dependency.new(:blueprint)
31
+ dependency.method1.method2(1).method3 {|val| val.method4 }
32
+
33
+ @mock.expects(:method1).with().returns(mock1 = mock)
34
+ mock1.expects(:method2).with(1).returns(mock2 = mock)
35
+ mock2.expects(:method3).with().yields(mock(:method4 => true)).returns(result = mock)
36
+
37
+ dependency.value.should == result
38
+ end
39
+ end
@@ -0,0 +1,23 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe Blueprints::Namespace do
4
+ before do
5
+ mock = @mock
6
+
7
+ old_root = Blueprints::Namespace.root
8
+ @namespace = Blueprints::Namespace.root = Blueprints::Namespace.new(:namespace)
9
+ Blueprints::Blueprint.new(:blueprint1, __FILE__) { mock }
10
+ Blueprints::Blueprint.new(:blueprint2, __FILE__) { mock }
11
+ Blueprints::Namespace.root = old_root
12
+
13
+ Blueprints::Blueprint.new(:outside_namespace, __FILE__) { mock }
14
+ Blueprints::Namespace.root.build :namespace
15
+ end
16
+
17
+ describe "demolish" do
18
+ it "should allow to demolish namespace" do
19
+ @mock.expects(:destroy).twice
20
+ @namespace.demolish
21
+ end
22
+ end
23
+ end
@@ -14,4 +14,13 @@ require 'lib/blueprints'
14
14
 
15
15
  Spec::Runner.configure do |config|
16
16
  config.mock_with :mocha
17
+
18
+ config.before do
19
+ Blueprints::Namespace.root.instance_variable_set(:@context, Blueprints::Context.new)
20
+ @mock = Mocha::Mockery.instance.unnamed_mock
21
+ end
22
+
23
+ config.after do
24
+ Blueprints::Namespace.root.children.clear
25
+ end
17
26
  end
@@ -91,37 +91,19 @@ class BlueprintsTest < ActiveSupport::TestCase
91
91
  end
92
92
 
93
93
  should "clear scenarios when calling demolish" do
94
- demolish
95
- assert(Fruit.count == 0)
96
- end
97
-
98
- should "clear only tables passed" do
99
- Tree.create!(:name => 'oak')
100
- demolish :fruits
101
- assert(Tree.count == 1)
102
- assert(Fruit.count == 0)
103
- end
104
-
105
- should "mark scenarios as undone when passed :undone option" do
106
- build :fruit
107
- demolish :undo => [:apple]
108
- assert(Fruit.count == 0)
109
- build :fruit
110
- assert(Fruit.count == 1)
94
+ demolish :apple
95
+ assert(!Fruit.all.include?(@apple))
96
+ build :apple
97
+ assert(Fruit.last == @apple)
111
98
  end
112
99
 
113
- should "mark all scenarios as undone when passed :undone option as :all" do
114
- build :fruit
115
- demolish :undo => :all
116
- assert(Fruit.count == 0)
117
- build :fruit
118
- assert(Fruit.count == 2)
119
- end
100
+ should "overwrite auto created instance variable with another auto created one" do
101
+ build :acorn => {:average_diameter => 3}
102
+ demolish :acorn
103
+ assert(@acorn.average_diameter == 3)
120
104
 
121
- should "raise error when not executed scenarios passed to :undo option" do
122
- assert_raise(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'orange'") do
123
- demolish :undo => :orange
124
- end
105
+ build :acorn => {:average_diameter => 5}
106
+ assert(@acorn.average_diameter == 5)
125
107
  end
126
108
  end
127
109
 
@@ -165,20 +147,20 @@ class BlueprintsTest < ActiveSupport::TestCase
165
147
 
166
148
  context 'errors' do
167
149
  should 'raise ScenarioNotFoundError when scenario could not be found' do
168
- assert_raise(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'not_existing'") do
150
+ assert_raise(Blueprints::BlueprintNotFoundError) do
169
151
  build :not_existing
170
152
  end
171
153
  end
172
154
 
173
155
  should 'raise ScenarioNotFoundError when scenario parent could not be found' do
174
- assert_raise(Blueprints::BlueprintNotFoundError, "Blueprint/namespace not found 'not_existing'") do
156
+ assert_raise(Blueprints::BlueprintNotFoundError) do
175
157
  build :parent_not_existing
176
158
  end
177
159
  end
178
160
 
179
161
  should 'raise TypeError when scenario name is not symbol or string' do
180
162
  assert_raise(TypeError, "Pass blueprint names as strings or symbols only, cannot define blueprint 1") do
181
- Blueprints::Blueprint.new(1)
163
+ Blueprints::Blueprint.new(1, __FILE__)
182
164
  end
183
165
  end
184
166
  end
@@ -211,6 +193,12 @@ class BlueprintsTest < ActiveSupport::TestCase
211
193
  assert(@oak.reload.size == 'updated')
212
194
  end
213
195
 
196
+ should "normalize attributes when updating with blueprint method" do
197
+ build :cherry, :oak
198
+ @cherry.blueprint(:tree => :@oak)
199
+ assert(@cherry.tree == @oak)
200
+ end
201
+
214
202
  should "automatically merge passed options" do
215
203
  build :oak => {:size => 'optional'}
216
204
  assert(@oak.name == 'Oak')
@@ -254,6 +242,7 @@ class BlueprintsTest < ActiveSupport::TestCase
254
242
  assert(!(@pitted_acorn.nil?))
255
243
  assert(!(@pitted_red_apple.nil?))
256
244
  assert_similar(@pitted, [@pitted_peach_tree, @pitted_peach, @pitted_acorn, [@pitted_red_apple]])
245
+ assert(build(:pitted) == @pitted)
257
246
  end
258
247
 
259
248
  context "with red namespace" do
@@ -307,15 +296,6 @@ class BlueprintsTest < ActiveSupport::TestCase
307
296
  end
308
297
  end
309
298
 
310
- should "overwrite auto created instance variable with another auto created one" do
311
- build :acorn => {:average_diameter => 3}
312
- demolish :fruits, :undo => :acorn
313
- assert(@acorn.average_diameter == 3)
314
-
315
- build :acorn => {:average_diameter => 5}
316
- assert(@acorn.average_diameter == 5)
317
- end
318
-
319
299
  context "extending blueprints" do
320
300
  should "allow to call build method inside blueprint body" do
321
301
  build :small_acorn
@@ -353,14 +333,8 @@ class BlueprintsTest < ActiveSupport::TestCase
353
333
  should "warn when blueprint with same name exists" do
354
334
  STDERR.expects(:puts).with("**WARNING** Overwriting existing blueprint: 'overwritten'")
355
335
  STDERR.expects(:puts).with(regexp_matches(/blueprints_(spec|test)\.rb:\d+:in `new'/))
356
- Blueprints::Blueprint.new(:overwritten)
357
- Blueprints::Blueprint.new(:overwritten)
358
- end
359
-
360
- should "warn when building with options and blueprint is already built" do
361
- STDERR.expects(:puts).with("**WARNING** Building with options, but blueprint was already built: 'big_cherry'")
362
- STDERR.expects(:puts).with(regexp_matches(/blueprints_(spec|test)\.rb:\d+/))
363
- build :big_cherry => {:species => 'some species'}
336
+ Blueprints::Blueprint.new(:overwritten, __FILE__)
337
+ Blueprints::Blueprint.new(:overwritten, __FILE__)
364
338
  end
365
339
 
366
340
  context 'attributes' do
@@ -384,6 +358,29 @@ class BlueprintsTest < ActiveSupport::TestCase
384
358
  build 'attributes.cherry'
385
359
  assert(@attributes_cherry.average_diameter == 10)
386
360
  end
361
+
362
+ should "return build attributes for dependencies" do
363
+ attrs = build_attributes('attributes.dependent_cherry1')
364
+ assert(!(@the_pine.nil?))
365
+ assert(attrs[:tree] == @the_pine)
366
+ end
367
+
368
+ should "return build attributes for :@var" do
369
+ attrs = build_attributes('attributes.dependent_cherry2')
370
+ assert(!(@the_pine.nil?))
371
+ assert(attrs[:tree] == @the_pine)
372
+ end
373
+ end
374
+
375
+ should "not fail with circular reference" do
376
+ build :circular_reference
387
377
  end
388
- end
389
378
 
379
+ should "rewrite trace" do
380
+ begin
381
+ build :error
382
+ rescue RuntimeError => e
383
+ assert(e.backtrace[0] == "spec/active_record/blueprint.rb:2:in blueprint 'error'")
384
+ end
385
+ end
386
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blueprints
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 63
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 3
10
- version: 0.7.3
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrius Chamentauskas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-17 00:00:00 +03:00
18
+ date: 2010-08-13 00:00:00 +03:00
19
19
  default_executable: blueprintify
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -79,10 +79,10 @@ files:
79
79
  - lib/blueprints/context.rb
80
80
  - lib/blueprints/convertable.rb
81
81
  - lib/blueprints/convertable/fixtures.rb
82
- - lib/blueprints/database_backends/active_record.rb
82
+ - lib/blueprints/core_ext.rb
83
+ - lib/blueprints/dependency.rb
83
84
  - lib/blueprints/errors.rb
84
85
  - lib/blueprints/extensions/cucumber.rb
85
- - lib/blueprints/extensions/deprecated.rb
86
86
  - lib/blueprints/extensions/rspec.rb
87
87
  - lib/blueprints/extensions/test_unit.rb
88
88
  - lib/blueprints/file_context.rb
@@ -101,7 +101,12 @@ files:
101
101
  - spec/no_db/fixtures/fruit.rb
102
102
  - spec/no_db/spec_helper.rb
103
103
  - spec/test_all.sh
104
+ - spec/unit/active_record_spec.rb
105
+ - spec/unit/blueprint_spec.rb
106
+ - spec/unit/buildable_spec.rb
104
107
  - spec/unit/configuration_spec.rb
108
+ - spec/unit/dependency_spec.rb
109
+ - spec/unit/namespace_spec.rb
105
110
  - spec/unit/spec_helper.rb
106
111
  - test/blueprints_test.rb
107
112
  - test/test_helper.rb
@@ -145,8 +150,13 @@ test_files:
145
150
  - spec/no_db/spec_helper.rb
146
151
  - spec/no_db/blueprints_spec.rb
147
152
  - spec/no_db/blueprint.rb
153
+ - spec/unit/active_record_spec.rb
154
+ - spec/unit/blueprint_spec.rb
148
155
  - spec/unit/spec_helper.rb
149
156
  - spec/unit/configuration_spec.rb
157
+ - spec/unit/namespace_spec.rb
158
+ - spec/unit/buildable_spec.rb
159
+ - spec/unit/dependency_spec.rb
150
160
  - spec/active_record/fixtures/fruit.rb
151
161
  - spec/active_record/fixtures/tree.rb
152
162
  - spec/active_record/fixtures/schema.rb
@@ -1,48 +0,0 @@
1
- module Blueprints
2
- # Extensions for active record class
3
- module ActiveRecordExtensions
4
- module ClassMethods
5
- # Two forms of this method can be used. First one is typically used inside blueprint block. Essentially it does
6
- # same as <tt>create!</tt>, except it does bypass attr_protected and attr_accessible. It accepts only a hash or attributes,
7
- # same as <tt>create!</tt> does.
8
- # blueprint :post => :user do
9
- # @user.posts.blueprint(:title => 'first post', :text => 'My first post')
10
- # end
11
- # The second form is used when you want to define new blueprint. It takes first argument as name of blueprint
12
- # and second one as hash of attributes. As you cannot use instance variables outside of blueprint block, you need
13
- # to prefix them with colon. So the example above could be rewritten like this:
14
- # Post.blueprint(:post, :title => 'first post', :text => 'My first post', :user => d(:user))
15
- # or like this:
16
- # Post.blueprint(:post, :title => 'first post', :text => 'My first post', :user => :@user).depends_on(:user)
17
- # or like this:
18
- # Post.blueprint({:post => :user}, :title => 'first post', :text => 'My first post', :user => :@user)
19
- def blueprint(name_or_attrs, attrs = {})
20
- if Blueprints::FileContext.current
21
- klass = self
22
- blueprint = Blueprints::Blueprint.new(name_or_attrs, Blueprints::FileContext.current.file) { klass.blueprint attributes }
23
- blueprint.attributes(attrs)
24
- blueprint
25
- else
26
- if name_or_attrs.is_a?(Array)
27
- name_or_attrs.collect { |attrs| blueprint(attrs) }
28
- else
29
- object = new
30
- object.blueprint(name_or_attrs)
31
- object
32
- end
33
- end
34
- end
35
- end
36
-
37
- module InstanceMethods
38
- # Updates attributes of object and calls save!. Bypasses attr_protected and attr_accessible.
39
- def blueprint(attributes)
40
- send(:attributes=, Blueprints::Blueprint.normalize_attributes(attributes.dup), false)
41
- save!
42
- end
43
- end
44
- end
45
- end
46
-
47
- ::ActiveRecord::Base.send(:include, Blueprints::ActiveRecordExtensions::InstanceMethods)
48
- ::ActiveRecord::Base.extend(Blueprints::ActiveRecordExtensions::ClassMethods)