object_momma 0.9.1 → 0.9.2

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/README.md CHANGED
@@ -192,6 +192,6 @@ ObjectMomma was written by Nathan Ladd, with help from a few partners in crime:
192
192
  * Josh Flanagan (jflanagan on github)
193
193
  * Theo Mills
194
194
 
195
- And, of course, I read about the ObjectMother pattern that I ruined^H^H^H^Himplemented from:
195
+ And, of course, I read about the ObjectMother pattern that I ~~ruined~~ implemented from:
196
196
 
197
197
  * Martin Fowler
@@ -6,6 +6,26 @@ module ObjectMomma
6
6
  attr_reader :actualize_strategy, :builder, :object_type
7
7
  alias_method :to_s, :child_id
8
8
 
9
+ def attributes_for_child
10
+ return {} unless ObjectMomma.use_serialized_attributes
11
+
12
+ # Pluralize
13
+ if object_type.to_s.chars.to_a.last == "s"
14
+ file_name = object_type
15
+ else
16
+ file_name = "#{object_type}s"
17
+ end
18
+
19
+ path = File.join(ObjectMomma.serialized_attributes_path, "#{file_name}.yml")
20
+
21
+ if File.size?(path)
22
+ attributes_by_child_id = YAML::load(ERB.new(File.read(path)).result)
23
+ return recursively_symbolize_hash(attributes_by_child_id.fetch(child_id, {}))
24
+ end
25
+
26
+ {}
27
+ end
28
+
9
29
  def initialize(object_type, hash, actualize_strategy)
10
30
  unless ACTUALIZE_STRATEGIES.include?(actualize_strategy)
11
31
  raise ArgumentError, "Invalid actualize strategy "\
@@ -84,28 +104,6 @@ module ObjectMomma
84
104
  object
85
105
  end
86
106
 
87
- def attributes_for_child
88
- return {} unless ObjectMomma.use_serialized_attributes
89
-
90
- # Pluralize
91
- if object_type.to_s.chars.to_a.last == "s"
92
- file_name = object_type
93
- else
94
- file_name = "#{object_type}s"
95
- end
96
-
97
- path = File.join(ObjectMomma.serialized_attributes_path, "#{file_name}.yml")
98
-
99
- if File.size?(path)
100
- File.open(path) do |yml_file|
101
- attributes_by_child_id = YAML::load(yml_file)
102
- return recursively_symbolize_hash(attributes_by_child_id.fetch(child_id, {}))
103
- end
104
- end
105
-
106
- {}
107
- end
108
-
109
107
  def recursively_symbolize_hash(hash = {})
110
108
  recurse = lambda { |in_hash|
111
109
  {}.tap do |out_hash|
@@ -7,6 +7,13 @@ module ObjectMomma
7
7
  def method_missing(method_name, *args, &block)
8
8
  return super unless respond_to?(method_name)
9
9
  return super if block_given?
10
+
11
+ object_type = object_type_from_attributes_getter(method_name)
12
+ if object_type
13
+ args.push(:find_or_create)
14
+ child = ObjectMomma::Child.new(object_type, *args)
15
+ return child.attributes_for_child
16
+ end
10
17
 
11
18
  object_type, actualize_strategy = object_type_and_actualize_strategy_from_method_name(method_name)
12
19
  args.push(actualize_strategy)
@@ -28,6 +35,21 @@ module ObjectMomma
28
35
  true
29
36
  end
30
37
 
38
+ def object_type_from_attributes_getter(method_name)
39
+ return nil unless ObjectMomma.use_serialized_attributes
40
+ match = method_name.to_s.match(%r{^(\w+)_attributes$}).to_a[1..-1]
41
+ return nil unless match
42
+
43
+ object_type = match[0]
44
+
45
+ begin
46
+ builder_for(object_type)
47
+ object_type
48
+ rescue NameError
49
+ nil
50
+ end
51
+ end
52
+
31
53
  def object_type_and_actualize_strategy_from_method_name(method_name)
32
54
  # Try ObjectMomma.user
33
55
  begin
@@ -57,6 +79,7 @@ module ObjectMomma
57
79
 
58
80
  def respond_to?(method_name, *args)
59
81
  return true if super
82
+ return true if object_type_from_attributes_getter(method_name)
60
83
  parse_method_name(method_name).nil? ? false : true
61
84
  end
62
85
 
@@ -1,3 +1,3 @@
1
1
  module ObjectMomma
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  Scott Pilgrim:
2
2
  email: foobar@zz.zzz
3
- username: lovemuscle23
3
+ username: <%= "lovemuscle23" %>
@@ -220,4 +220,16 @@ describe ObjectMomma do
220
220
  }.should_not raise_error(ObjectMomma::ObjectExists)
221
221
  end
222
222
  end
223
+
224
+ context ".(object_type)_attributes" do
225
+ before { ObjectMomma.use_serialized_attributes = true }
226
+ after { ObjectMomma.use_serialized_attributes = false }
227
+
228
+ it "returns a symbolized hash from the yml file corresponding to the object type" do
229
+ ObjectMomma.user_attributes("Scott Pilgrim").should == {
230
+ email: "foobar@zz.zzz",
231
+ username: "lovemuscle23"
232
+ }
233
+ end
234
+ end
223
235
  end
metadata CHANGED
@@ -1,45 +1,40 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: object_momma
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 9
8
- - 1
9
- version: 0.9.1
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.9.2
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - Nathan Ladd
13
9
  - Joshua Flanagan
14
10
  autorequire:
15
11
  bindir: bin
16
12
  cert_chain: []
17
-
18
- date: 2012-11-28 00:00:00 -06:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
13
+ date: 2012-11-29 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ none: false
22
22
  name: rspec
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
- version: "0"
31
23
  type: :development
32
- version_requirements: *id001
24
+ prerelease: false
25
+ requirement: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ none: false
33
31
  description: object_momma is an Object Mother implementation in ruby
34
- email:
32
+ email:
35
33
  - nathan@peopleadmin.com
36
34
  executables: []
37
-
38
35
  extensions: []
39
-
40
36
  extra_rdoc_files: []
41
-
42
- files:
37
+ files:
43
38
  - .gitignore
44
39
  - Gemfile
45
40
  - LICENSE
@@ -63,37 +58,33 @@ files:
63
58
  - spec/fixtures/vote.rb
64
59
  - spec/object_momma_spec.rb
65
60
  - tmp/.gitkeep
66
- has_rdoc: true
67
61
  homepage: https://github.com/PeopleAdmin/object_momma
68
- licenses:
62
+ licenses:
69
63
  - MIT
70
64
  post_install_message:
71
65
  rdoc_options: []
72
-
73
- require_paths:
66
+ require_paths:
74
67
  - lib
75
- required_ruby_version: !ruby/object:Gem::Requirement
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- segments:
80
- - 0
81
- version: "0"
82
- required_rubygems_version: !ruby/object:Gem::Requirement
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- segments:
87
- - 0
88
- version: "0"
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ none: false
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ none: false
89
80
  requirements: []
90
-
91
81
  rubyforge_project:
92
- rubygems_version: 1.3.6
82
+ rubygems_version: 1.8.23
93
83
  signing_key:
94
84
  specification_version: 3
95
- summary: object_momma is an Object Mother implementation in ruby; it is designed to facilitate complex data setup for acceptance tests.
96
- test_files:
85
+ summary: object_momma is an Object Mother implementation in ruby; it is designed to
86
+ facilitate complex data setup for acceptance tests.
87
+ test_files:
97
88
  - spec/fixtures/blog_post_voting_classes.rb
98
89
  - spec/fixtures/comment.rb
99
90
  - spec/fixtures/fake_model.rb