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 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
- There's also a shorthand for these type of scenarios:
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
- All blueprints are run only once, no matter how many times they were called, meaning that you don't need to worry about
64
- duplicating data.
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 {|attr, value| object.send("#{attr}=", value)}
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
@@ -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, @parents = parse_name(scenario)
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
@@ -38,4 +38,6 @@ Tree.blueprint :oak, :name => 'Oak', :size => 'large'
38
38
 
39
39
  blueprint :pine do
40
40
  @the_pine = Tree.blueprint :name => 'Pine', :size => 'medium'
41
- end
41
+ end
42
+
43
+ Fruit.blueprint(:acorn, :species => 'Acorn', :tree => :@oak).depends_on(:oak)
@@ -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
@@ -1,2 +1,3 @@
1
1
  class Fruit < ActiveRecord::Base
2
+ belongs_to :tree
2
3
  end
data/spec/db/schema.rb CHANGED
@@ -2,6 +2,7 @@ ActiveRecord::Schema.define(:version => 0) do
2
2
  create_table :fruits, :force => true do |t|
3
3
  t.string :species
4
4
  t.integer :average_diameter
5
+ t.belongs_to :tree
5
6
  end
6
7
 
7
8
  create_table :trees, :force => true do |t|
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.0
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-01 00:00:00 +03:00
12
+ date: 2009-10-02 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency