blueprints 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +19 -3
- data/lib/blueprints/ar_extensions.rb +4 -1
- data/lib/blueprints/plan.rb +8 -3
- data/spec/blueprints.rb +3 -1
- data/spec/blueprints_spec.rb +7 -0
- data/spec/db/fruit.rb +1 -0
- data/spec/db/schema.rb +1 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -50,7 +50,12 @@ inside 'blueprint' block and they will be accessible in tests that build this bl
|
|
50
50
|
Instead of SomeModel.create! you can also use SomeModel.blueprint, which does the same thing but also bypasses attr_protected
|
51
51
|
and attr_accessible restrictions (which is what you usually want in tests).
|
52
52
|
|
53
|
-
|
53
|
+
All blueprints are run only once, no matter how many times they were called, meaning that you don't need to worry about
|
54
|
+
duplicating data.
|
55
|
+
|
56
|
+
=== Shorthands ===
|
57
|
+
|
58
|
+
There's a shorthand for these type of scenarios:
|
54
59
|
|
55
60
|
blueprint :something do
|
56
61
|
@something = SomeModel.blueprint :field => 'value'
|
@@ -60,8 +65,19 @@ You can just type:
|
|
60
65
|
|
61
66
|
SomeModel.blueprint :something, :field => 'value'
|
62
67
|
|
63
|
-
|
64
|
-
|
68
|
+
If you need to make associations then:
|
69
|
+
|
70
|
+
SomeModel.blueprint :something, :associated_column => :@association_instance_variable
|
71
|
+
|
72
|
+
And if you also need it to depend on other blueprints:
|
73
|
+
|
74
|
+
SomeModel.blueprint({:something => :some_blueprint}, :associated_column => :@some_iv)
|
75
|
+
|
76
|
+
...or...
|
77
|
+
|
78
|
+
SomeModel.blueprint(:something, :associated_column => :@some_iv).depends_on(:some_blueprint) # I prefer this one
|
79
|
+
|
80
|
+
=== Blueprints file ===
|
65
81
|
|
66
82
|
Blueprints searches for blueprints files in this particular order in Rails (Merb) root:
|
67
83
|
* blueprints.rb
|
@@ -11,7 +11,10 @@ module ActiveRecord
|
|
11
11
|
end
|
12
12
|
else
|
13
13
|
returning(self.new) do |object|
|
14
|
-
options.each
|
14
|
+
options.each do |attr, value|
|
15
|
+
value = Blueprints::Plan.context.instance_variable_get(value) if value.is_a? Symbol and value.to_s =~ /^@.+$/
|
16
|
+
object.send("#{attr}=", value)
|
17
|
+
end
|
15
18
|
object.save!
|
16
19
|
end
|
17
20
|
end
|
data/lib/blueprints/plan.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Blueprints
|
2
2
|
class Plan
|
3
|
-
cattr_reader :plans
|
3
|
+
cattr_reader :plans, :context
|
4
4
|
cattr_accessor :executed_plans
|
5
5
|
@@plans = {}
|
6
6
|
@@executed_plans = Set.new
|
@@ -35,8 +35,9 @@ module Blueprints
|
|
35
35
|
|
36
36
|
attr_reader :name
|
37
37
|
|
38
|
-
def initialize(scenario, &block)
|
39
|
-
@name,
|
38
|
+
def initialize(*scenario, &block)
|
39
|
+
@name, parents = parse_name(*scenario)
|
40
|
+
depends_on(*parents)
|
40
41
|
@block = block
|
41
42
|
|
42
43
|
@@plans[@name] = self
|
@@ -47,6 +48,10 @@ module Blueprints
|
|
47
48
|
build_plan(@@context)
|
48
49
|
end
|
49
50
|
|
51
|
+
def depends_on(*scenarios)
|
52
|
+
@parents = (@parents || []) + scenarios.map{|s| s.to_sym}
|
53
|
+
end
|
54
|
+
|
50
55
|
protected
|
51
56
|
|
52
57
|
def parse_name(name)
|
data/spec/blueprints.rb
CHANGED
data/spec/blueprints_spec.rb
CHANGED
@@ -217,6 +217,13 @@ describe Blueprints do
|
|
217
217
|
@the_pine.name.should == 'Pine'
|
218
218
|
@the_pine.size.should == 'medium'
|
219
219
|
end
|
220
|
+
|
221
|
+
it "should associate acorn with oak correctly" do
|
222
|
+
build :acorn
|
223
|
+
@oak.should_not be_nil
|
224
|
+
@acorn.should_not be_nil
|
225
|
+
@acorn.tree.should == @oak
|
226
|
+
end
|
220
227
|
end
|
221
228
|
|
222
229
|
#describe "with pitted namespace" do
|
data/spec/db/fruit.rb
CHANGED
data/spec/db/schema.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blueprints
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrius Chamentauskas
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-10-
|
12
|
+
date: 2009-10-02 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|