mdoel-cukesteps 0.3.1 → 0.6.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.
data/README.rdoc CHANGED
@@ -16,7 +16,8 @@ Right now, there's just one and it is of the form:
16
16
 
17
17
  This is expected to be used with a step table and allows for complex associations to be built up
18
18
  in concise language. Consider an application with models for restaurant, brand, employee, and
19
- location. You might want to create a test world like:
19
+ location. Brand instances are pre-seeded into your database (e.g. for dropdown lists and other
20
+ similar uses). You might want to create a test world like:
20
21
 
21
22
  Given the following employees exist
22
23
  | employee | name |
@@ -30,16 +31,18 @@ location. You might want to create a test world like:
30
31
 
31
32
  If you put the following in your features/support/env.rb file:
32
33
 
33
- cuke_association_builders(:brand => :build_associated_via_find_by_name,
34
- :location => :from_factory)
34
+ cuke_association_attributes(:brand => :name,
35
+ :location => :address)
35
36
 
36
37
  then each Restaurant object gets created and associated with three other model objects:
37
38
  - Brand - via a find_by_name lookup inside the brands table
38
- - Location - via the return of the Location#from_factory class method
39
+ - Location - via the return of the create_location(:address => address) factory method (e.g. from FixtureReplacemnt)
39
40
  - Employee - from the objects created in the previous step
40
41
 
41
- Note that in the above, :build_associated_via_find_by_name is the only "magic" value to associate with
42
- a model/table column.
42
+ For items passed to the cuke_association_attributes method, the basic logic used in finding the
43
+ objects to use for the association is:
44
+ - Try a find_by_attribute method. If that returns a non-nil value, it is used. Otherwise
45
+ - Use a FixtureReplacement-like create_model factory method built from the attribute and value
43
46
 
44
47
  = General Debugging/Development steps
45
48
  These steps are not typically ones you would leave inside your cucumber features file as they are
@@ -66,15 +69,15 @@ in the search results" ensures that the the page contains an element of class ph
66
69
  search-results.
67
70
 
68
71
  The steps available here are:
69
- - Then I should see the foo
70
- - Then I should see a|an foo
71
- - Then I should see a foo in the bar
72
- - Then I should see the foo in the bar
73
- - Then I should see n foos in the bar
74
- - Then I should see n to m foos in the bar
75
- - Then the baz in the bar should contain a foo
72
+ - Then I should see the foo (e.g. Then I should see the search-results)
73
+ - Then I should see a|an foo (e.g. Then I should see a listing)
74
+ - Then I should see a foo in the bar (e.g. Then I should see a listing in the search-results)
75
+ - Then I should see the foo in the bar (e.g. Then I should see the map in the search-results)
76
+ - Then I should see n foos in the bar (e.g. Then I should see 4 listings in the search-results)
77
+ - Then I should see n to m foos in the bar (e.g. Then I should see 3 to 5 listings in the search-results)
78
+ - Then the baz in the bar should contain a foo (e.g. Then the map in the search-results should contain a resizer)
76
79
 
77
- The negation of each of the above is also available (e.g. Then I should not see a foo in the bar)
80
+ The negation of each of the above is also available (e.g. Then I should not see a listing in the search-results)
78
81
 
79
82
  = Installation/Use
80
83
  To install the gem, use:
@@ -86,8 +89,8 @@ To use it, add the following to your features/support/env.rb file:
86
89
 
87
90
  require 'mdoel-cukesteps'
88
91
  include CukeAssociationhelpers
89
- cuke_association_builders(:model1 => :class_method_1,
90
- :model2 => :build_associated_via_find_by_name)
92
+ cuke_association_attributes(:model1 => :attribute_1
93
+ :model2 => :attribute_2)
91
94
 
92
95
 
93
96
  = To Do
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.6.0
data/cukesteps.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{cukesteps}
5
- s.version = "0.3.1"
5
+ s.version = "0.6.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Mike Doel"]
@@ -1,6 +1,6 @@
1
1
  module CukeAssociationHelpers
2
2
 
3
- def cuke_association_builders(associations = {})
3
+ def cuke_association_attributes(associations = {})
4
4
  @@associated_cuke_builders ||= {}
5
5
  associations.each { |k,v| @@associated_cuke_builders[k] = v }
6
6
  end
@@ -62,12 +62,12 @@ module CukeAssociationHelpers
62
62
 
63
63
  def build_value_from_association(key,value)
64
64
  klass = class_from_symbol(key)
65
- builder = @@associated_cuke_builders[key]
66
- if builder == :build_associated_via_find_by_name
67
- klass.find_by_name(value)
68
- else
69
- klass.send(builder,value)
65
+ builder_attribute = @@associated_cuke_builders[key]
66
+ built_object = klass.send("find_by_#{builder_attribute}", value)
67
+ if built_object.nil?
68
+ built_object = create_model(key.to_s,{builder_attribute.to_sym => value})
70
69
  end
70
+ built_object
71
71
  end
72
72
 
73
73
  def class_from_symbol(key)
data/lib/cukesteps.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'common_steps'
2
- #require 'lib/cuke_association_helpers.rb'
2
+ require 'cuke_association_helpers.rb'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdoel-cukesteps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Doel