blueprints 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  html
4
4
  spec/active_record/fixtures/database.yml
5
5
  debug.log
6
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1 @@
1
+ gemspec
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ blueprints (0.8.0)
5
+ activesupport (>= 2.3.0)
6
+ database_cleaner (~> 0.5.0)
7
+
8
+ GEM
9
+ specs:
10
+ activerecord (2.3.8)
11
+ activesupport (= 2.3.8)
12
+ activesupport (2.3.8)
13
+ builder (2.1.2)
14
+ cucumber (0.7.3)
15
+ builder (>= 2.1.2)
16
+ diff-lcs (>= 1.1.2)
17
+ gherkin (>= 1.0.27)
18
+ json_pure (>= 1.2.4)
19
+ term-ansicolor (>= 1.0.4)
20
+ database_cleaner (0.5.2)
21
+ diff-lcs (1.1.2)
22
+ gherkin (1.0.30)
23
+ trollop (>= 1.16.2)
24
+ json_pure (1.2.4)
25
+ mocha (0.9.8)
26
+ rake
27
+ rake (0.8.7)
28
+ rspec (1.3.0)
29
+ shoulda (2.10.3)
30
+ term-ansicolor (1.0.5)
31
+ trollop (1.16.2)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ activerecord (>= 2.3.0)
38
+ activesupport (>= 2.3.0)
39
+ blueprints!
40
+ cucumber (>= 0.7.0)
41
+ database_cleaner (~> 0.5.0)
42
+ mocha (>= 0.9.8)
43
+ rspec (>= 1.3.0)
44
+ shoulda (>= 2.10.0)
data/Rakefile CHANGED
@@ -12,6 +12,11 @@ begin
12
12
  gemspec.executables = ['blueprintify']
13
13
  gemspec.add_dependency 'activesupport', '>=2.3.0'
14
14
  gemspec.add_dependency 'database_cleaner', '~>0.5.0'
15
+ gemspec.add_development_dependency 'rspec', '>=1.3.0'
16
+ gemspec.add_development_dependency 'activerecord', '>=2.3.0'
17
+ gemspec.add_development_dependency 'mocha', '>=0.9.8'
18
+ gemspec.add_development_dependency 'shoulda', '>=2.10.0'
19
+ gemspec.add_development_dependency 'cucumber', '>=0.7.0'
15
20
  end
16
21
  Jeweler::GemcutterTasks.new
17
22
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.0
1
+ 0.8.1
File without changes
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{blueprints}
8
- s.version = "0.8.0"
8
+ s.version = "0.8.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Andrius Chamentauskas"]
12
- s.date = %q{2010-08-13}
12
+ s.date = %q{2010-09-07}
13
13
  s.default_executable = %q{blueprintify}
14
14
  s.description = %q{Another replacement for factories and fixtures. The library that lazy typists will love}
15
15
  s.email = %q{sinsiliux@gmail.com}
@@ -20,6 +20,8 @@ Gem::Specification.new do |s|
20
20
  ]
21
21
  s.files = [
22
22
  ".gitignore",
23
+ "Gemfile",
24
+ "Gemfile.lock",
23
25
  "LICENSE",
24
26
  "README.rdoc",
25
27
  "Rakefile",
@@ -105,13 +107,28 @@ Gem::Specification.new do |s|
105
107
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
106
108
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.0"])
107
109
  s.add_runtime_dependency(%q<database_cleaner>, ["~> 0.5.0"])
110
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
111
+ s.add_development_dependency(%q<activerecord>, [">= 2.3.0"])
112
+ s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
113
+ s.add_development_dependency(%q<shoulda>, [">= 2.10.0"])
114
+ s.add_development_dependency(%q<cucumber>, [">= 0.7.0"])
108
115
  else
109
116
  s.add_dependency(%q<activesupport>, [">= 2.3.0"])
110
117
  s.add_dependency(%q<database_cleaner>, ["~> 0.5.0"])
118
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
119
+ s.add_dependency(%q<activerecord>, [">= 2.3.0"])
120
+ s.add_dependency(%q<mocha>, [">= 0.9.8"])
121
+ s.add_dependency(%q<shoulda>, [">= 2.10.0"])
122
+ s.add_dependency(%q<cucumber>, [">= 0.7.0"])
111
123
  end
112
124
  else
113
125
  s.add_dependency(%q<activesupport>, [">= 2.3.0"])
114
126
  s.add_dependency(%q<database_cleaner>, ["~> 0.5.0"])
127
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
128
+ s.add_dependency(%q<activerecord>, [">= 2.3.0"])
129
+ s.add_dependency(%q<mocha>, [">= 0.9.8"])
130
+ s.add_dependency(%q<shoulda>, [">= 2.10.0"])
131
+ s.add_dependency(%q<cucumber>, [">= 0.7.0"])
115
132
  end
116
133
  end
117
134
 
@@ -7,7 +7,7 @@ module Blueprints
7
7
  @file = file
8
8
  super(name)
9
9
 
10
- ivname = :"@#{path}"
10
+ ivname = variable_name
11
11
  @block = block
12
12
  @demolish_block = lambda { instance_variable_get(ivname).destroy }
13
13
  @update_block = lambda { instance_variable_get(ivname).blueprint(options) }
@@ -19,7 +19,7 @@ module Blueprints
19
19
  if built? and build_once
20
20
  Namespace.root.context.instance_eval(&@update_block) if RootNamespace.root.context.options.present?
21
21
  elsif @block
22
- @result = Namespace.root.context.instance_eval(&@block)
22
+ self.result = Namespace.root.context.instance_eval(&@block)
23
23
  end
24
24
  end
25
25
  end
@@ -27,8 +27,8 @@ module Blueprints
27
27
  #
28
28
  # +options+ - list of options to be accessible in the body of a blueprint. Defaults to empty Hash.
29
29
  def build(build_once = true, options = {})
30
- return @result if (built? or Namespace.root.executed_blueprints.include? self) and build_once and options.blank?
31
- Namespace.root.executed_blueprints << self
30
+ return result if @building or (built? and build_once and options.blank?)
31
+ @building = true
32
32
 
33
33
  each_namespace {|namespace| namespace.build_parents }
34
34
  build_parents
@@ -39,17 +39,28 @@ module Blueprints
39
39
 
40
40
  build_self(build_once)
41
41
  Namespace.root.context.options, Namespace.root.context.attributes = old_options, old_attributes
42
- Namespace.root.add_variable(path, @result)
42
+ Namespace.root.executed_blueprints << self
43
+ @building = false
44
+ result
45
+ end
46
+
47
+ # Returns the result of blueprint
48
+ def result
49
+ Namespace.root.context.instance_variable_get(variable_name)
50
+ end
51
+
52
+ # Sets the result of blueprint
53
+ def result=(value)
54
+ Namespace.root.add_variable(variable_name, value)
43
55
  end
44
56
 
45
57
  # Returns if blueprint has been built
46
58
  def built?
47
- instance_variable_defined?(:@result)
59
+ Namespace.root.executed_blueprints.include?(self)
48
60
  end
49
61
 
50
62
  # Marks blueprint as not built
51
63
  def undo!
52
- remove_instance_variable(:@result) if built?
53
64
  Namespace.root.executed_blueprints.delete self
54
65
  end
55
66
 
@@ -100,6 +111,10 @@ module Blueprints
100
111
  @path = (namespace.path + "_" unless namespace.nil? or namespace.path.empty?).to_s + @name.to_s
101
112
  end
102
113
 
114
+ def variable_name
115
+ :"@#{path}"
116
+ end
117
+
103
118
  def parse_name(name)
104
119
  case name
105
120
  when Hash
@@ -31,7 +31,7 @@ module Blueprints
31
31
 
32
32
  # Builds all children and sets instance variable named by name of namespace with the results.
33
33
  def build_self(build_once = true)
34
- @result = @children.collect {|p| p.last.build }.uniq
34
+ self.result = @children.collect {|p| p.last.build }.uniq
35
35
  end
36
36
 
37
37
  # Demolished all child blueprints and namespaces
@@ -59,8 +59,7 @@ module Blueprints
59
59
  # Sets instance variable in current context to passed value. If instance variable with same name already exists, it
60
60
  # is set only if it was set using this same method
61
61
  def add_variable(name, value)
62
- name = "@#{name}" unless name.to_s[0, 1] == "@"
63
- if !@context.instance_variable_get(name) or @auto_iv_list.include?(name)
62
+ if not @context.instance_variable_defined?(name) or @auto_iv_list.include?(name)
64
63
  @auto_iv_list << name
65
64
  @context.instance_variable_set(name, value)
66
65
  end
@@ -107,6 +107,13 @@ describe Blueprints do
107
107
  end
108
108
  end
109
109
 
110
+ describe "updating" do
111
+ it "should allow updating prebuilt blueprints" do
112
+ build :big_cherry => {:species => 'updated cherry'}
113
+ @big_cherry.species.should == 'updated cherry'
114
+ end
115
+ end
116
+
110
117
  describe 'with many apples scenario' do
111
118
  before do
112
119
  build :many_apples, :cherry, :cherry_basket
@@ -17,12 +17,7 @@ describe Blueprints::Blueprint do
17
17
  @blueprint.demolish
18
18
  end
19
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
20
+ it "should raise error if blueprint is not built" do
26
21
  @blueprint.demolish
27
22
  lambda { @blueprint.demolish }.should raise_error(Blueprints::DemolishError)
28
23
  end
@@ -22,5 +22,6 @@ Spec::Runner.configure do |config|
22
22
 
23
23
  config.after do
24
24
  Blueprints::Namespace.root.children.clear
25
+ Blueprints::Namespace.root.executed_blueprints.clear
25
26
  end
26
27
  end
@@ -107,6 +107,13 @@ class BlueprintsTest < ActiveSupport::TestCase
107
107
  end
108
108
  end
109
109
 
110
+ context "updating" do
111
+ should "allow updating prebuilt blueprints" do
112
+ build :big_cherry => {:species => 'updated cherry'}
113
+ assert(@big_cherry.species == 'updated cherry')
114
+ end
115
+ end
116
+
110
117
  context 'with many apples scenario' do
111
118
  setup do
112
119
  build :many_apples, :cherry, :cherry_basket
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: 63
4
+ hash: 61
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 0
10
- version: 0.8.0
9
+ - 1
10
+ version: 0.8.1
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-08-13 00:00:00 +03:00
18
+ date: 2010-09-07 00:00:00 +03:00
19
19
  default_executable: blueprintify
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -50,6 +50,86 @@ dependencies:
50
50
  version: 0.5.0
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ hash: 27
62
+ segments:
63
+ - 1
64
+ - 3
65
+ - 0
66
+ version: 1.3.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ hash: 3
78
+ segments:
79
+ - 2
80
+ - 3
81
+ - 0
82
+ version: 2.3.0
83
+ type: :development
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: mocha
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 43
94
+ segments:
95
+ - 0
96
+ - 9
97
+ - 8
98
+ version: 0.9.8
99
+ type: :development
100
+ version_requirements: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: shoulda
103
+ prerelease: false
104
+ requirement: &id006 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ hash: 39
110
+ segments:
111
+ - 2
112
+ - 10
113
+ - 0
114
+ version: 2.10.0
115
+ type: :development
116
+ version_requirements: *id006
117
+ - !ruby/object:Gem::Dependency
118
+ name: cucumber
119
+ prerelease: false
120
+ requirement: &id007 !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ hash: 3
126
+ segments:
127
+ - 0
128
+ - 7
129
+ - 0
130
+ version: 0.7.0
131
+ type: :development
132
+ version_requirements: *id007
53
133
  description: Another replacement for factories and fixtures. The library that lazy typists will love
54
134
  email: sinsiliux@gmail.com
55
135
  executables:
@@ -61,6 +141,8 @@ extra_rdoc_files:
61
141
  - README.rdoc
62
142
  files:
63
143
  - .gitignore
144
+ - Gemfile
145
+ - Gemfile.lock
64
146
  - LICENSE
65
147
  - README.rdoc
66
148
  - Rakefile