featured_model 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.sw?
2
+ *.tmproj
2
3
  .DS_Store
3
4
  coverage
4
5
  rdoc
data/README.rdoc CHANGED
@@ -1,9 +1,58 @@
1
- = featured_model
1
+ h1. featured_model
2
2
 
3
- Cucumber step definitions to create model instances with dynamic attributes and associations.
3
+ Warning! As reflected by the incredibly low version number, this is a new work in progress. We are sharing it with you early and often in the hope you will find it useful and help us make it better quicker.
4
+
5
+ We love using "fixjour":http://github.com/nakajima/fixjour in RSpec for creating test instances of our models. featured_model allows us the same flexibility in Cucumber.
6
+
7
+ For example, doing this in RSpec:
8
+ <pre>@address = create_address(:city => "Madison", :state => "WI", :zip_code => "53703")
9
+ @order = create_order(:status => "open", :order_id_amazon => "1234", :address => @address)</pre>
10
+
11
+ can be done in Cucumber as:
12
+ <pre>Given a new address with city "Madison" and state "WI" and zip code "53703"
13
+ And a new order with status "open" and order id amazon "1234" for address with city "Madison"</pre>
14
+
15
+ h2. Installation
16
+
17
+ coming soon...
18
+
19
+ h2. Usage
20
+
21
+ Start your call off with @"a new <model-name>"@ where @<model-name>@ is a lower case version of the class name you want to build with fixjour. Underscores can be replaced with spaces.
22
+
23
+ For example:
24
+ <pre>Given a new address</pre>
25
+
26
+ | actual class name | @<model-name>@ |
27
+ | Order | order |
28
+ | LineItem | line item |
29
+
30
+ h3. Add attribute values
31
+
32
+ Add the first attribute to your call using the @'with'@ operator:
33
+ <pre>Given a new address with city "Madison"</pre>
34
+
35
+ Add as many additional attributes as you want using the @'and'@ operator:
36
+ <pre>Given a new address with city "Madison" and state "WI" and zip code "53703"</pre>
37
+
38
+ h3. Add associations
39
+
40
+ We specify the associated object using attributes, instead of ActiveRecord id numbers. This is more in the spirit of functional Cucumber testing to not depend on details an end user would not understand.
41
+
42
+ Use the @'for'@ operator to specify an association. You must give the association enough attributes to find the correct, desired associated object in the database.
43
+
44
+ In this example, we create a new order and setting its address to the address created on the line before.
45
+ <pre>Given a new address with city "Madison" and state "WI" and zip code "53703"
46
+ And a new order with status "open" and order id amazon "1234" for address with city "Madison"</pre>
47
+
48
+ Note how we did not have to specify all the attributes for the associated object. We just give the minimal attributes in order to find the correct object. In this case, city "Madison" is enough since there is no other address in the database with city set to "Madison". If your test has more addresses in play, then you'll need to specify more attributes.
49
+
50
+ In other words, the example above can also be written as:
51
+ <pre>Given a new address with city "Madison" and state "WI" and zip code "53703"
52
+ And a new order with status "open" and order id amazon "1234" for address with city "Madison" and state "WI" and zip code "53703"</pre>
53
+
54
+ h2. Note on Patches/Pull Requests
4
55
 
5
- == Note on Patches/Pull Requests
6
-
7
56
  * Fork the project.
8
57
  * Make your feature addition or bug fix.
9
58
  * Add tests for it. This is important so I don't break it in a
@@ -13,11 +62,14 @@ Cucumber step definitions to create model instances with dynamic attributes and
13
62
  bump version in a commit by itself I can ignore when I pull)
14
63
  * Send me a pull request. Bonus points for topic branches.
15
64
 
16
- == Contributors
65
+ h2. Contributors
66
+
17
67
  listrophy
18
68
  bendycode
19
69
  coreyhaines
70
+ arta
71
+ randland
20
72
 
21
- == Copyright
73
+ h2. Copyright
22
74
 
23
75
  Copyright (c) 2009 bendyworks. See LICENSE for details.
data/README.textile ADDED
@@ -0,0 +1,75 @@
1
+ h1. featured_model
2
+
3
+ Warning! As reflected by the incredibly low version number, this is a new work in progress. We are sharing it with you early and often in the hope you will find it useful and help us make it better quicker.
4
+
5
+ We love using "fixjour":http://github.com/nakajima/fixjour in RSpec for creating test instances of our models. featured_model allows us the same flexibility in Cucumber.
6
+
7
+ For example, doing this in RSpec:
8
+ <pre>@address = create_address(:city => "Madison", :state => "WI", :zip_code => "53703")
9
+ @order = create_order(:status => "open", :order_id_amazon => "1234", :address => @address)</pre>
10
+
11
+ can be done in Cucumber as:
12
+ <pre>Given a new address with city "Madison" and state "WI" and zip code "53703"
13
+ And a new order with status "open" and order id amazon "1234" for address with city "Madison"</pre>
14
+
15
+ h2. Installation
16
+
17
+ coming soon...
18
+
19
+ h2. Usage
20
+
21
+ Start your call off with @"a new <model-name>"@ where @<model-name>@ is a lower case version of the class name you want to build with fixjour. Underscores can be replaced with spaces.
22
+
23
+ For example:
24
+ <pre>Given a new address</pre>
25
+
26
+ | actual class name | @<model-name>@ |
27
+ | Order | order |
28
+ | LineItem | line item |
29
+
30
+ h3. Add attribute values
31
+
32
+ Add the first attribute to your call using the @'with'@ operator:
33
+ <pre>Given a new address with city "Madison"</pre>
34
+
35
+ Add as many additional attributes as you want using the @'and'@ operator:
36
+ <pre>Given a new address with city "Madison" and state "WI" and zip code "53703"</pre>
37
+
38
+ h3. Add associations
39
+
40
+ We specify the associated object using attributes, instead of ActiveRecord id numbers. This is more in the spirit of functional Cucumber testing to not depend on details an end user would not understand.
41
+
42
+ Use the @'for'@ operator to specify an association. You must give the association enough attributes to find the correct, desired associated object in the database.
43
+
44
+ In this example, we create a new order and setting its address to the address created on the line before.
45
+ <pre>Given a new address with city "Madison" and state "WI" and zip code "53703"
46
+ And a new order with status "open" and order id amazon "1234" for address with city "Madison"</pre>
47
+
48
+ Note how we did not have to specify all the attributes for the associated object. We just give the minimal attributes in order to find the correct object. In this case, city "Madison" is enough since there is no other address in the database with city set to "Madison". If your test has more addresses in play, then you'll need to specify more attributes.
49
+
50
+ In other words, the example above can also be written as:
51
+ <pre>Given a new address with city "Madison" and state "WI" and zip code "53703"
52
+ And a new order with status "open" and order id amazon "1234" for address with city "Madison" and state "WI" and zip code "53703"</pre>
53
+
54
+ h2. Note on Patches/Pull Requests
55
+
56
+ * Fork the project.
57
+ * Make your feature addition or bug fix.
58
+ * Add tests for it. This is important so I don't break it in a
59
+ future version unintentionally.
60
+ * Commit, do not mess with rakefile, version, or history.
61
+ (if you want to have your own version, that is fine but
62
+ bump version in a commit by itself I can ignore when I pull)
63
+ * Send me a pull request. Bonus points for topic branches.
64
+
65
+ h2. Contributors
66
+
67
+ listrophy
68
+ bendycode
69
+ coreyhaines
70
+ arta
71
+ randland
72
+
73
+ h2. Copyright
74
+
75
+ Copyright (c) 2009 bendyworks. See LICENSE for details.
data/Rakefile CHANGED
@@ -9,11 +9,12 @@ begin
9
9
  gem.description = %Q{Additional steps that add a bunch of functionality for creating models with one line}
10
10
  gem.email = "stephen@bendyworks.com"
11
11
  gem.homepage = "http://github.com/bendyworks/featured_model"
12
- gem.authors = ["bendycode"]
13
- gem.add_development_dependency "rspec"
14
- gem.add_development_dependency "cucumber"
12
+ gem.authors = ["bendycode", 'listrophy', 'arta', 'randland']
13
+ gem.add_development_dependency "fixjour"
14
+ # gem.add_development_dependency "cucumber"
15
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
16
  end
17
+ Jeweler::GemcutterTasks.new
17
18
  rescue LoadError
18
19
  puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
20
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
@@ -5,22 +5,24 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{featured_model}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["bendycode"]
12
- s.date = %q{2009-10-06}
11
+ s.authors = ["bendycode", "listrophy", "arta", "randland"]
12
+ s.date = %q{2009-10-30}
13
13
  s.description = %q{Additional steps that add a bunch of functionality for creating models with one line}
14
14
  s.email = %q{stephen@bendyworks.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
- "README.rdoc"
17
+ "README.rdoc",
18
+ "README.textile"
18
19
  ]
19
20
  s.files = [
20
21
  ".document",
21
22
  ".gitignore",
22
23
  "LICENSE",
23
24
  "README.rdoc",
25
+ "README.textile",
24
26
  "Rakefile",
25
27
  "VERSION",
26
28
  "featured_model.gemspec",
@@ -43,14 +45,11 @@ Gem::Specification.new do |s|
43
45
  s.specification_version = 3
44
46
 
45
47
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<rspec>, [">= 0"])
47
- s.add_development_dependency(%q<cucumber>, [">= 0"])
48
+ s.add_development_dependency(%q<fixjour>, [">= 0"])
48
49
  else
49
- s.add_dependency(%q<rspec>, [">= 0"])
50
- s.add_dependency(%q<cucumber>, [">= 0"])
50
+ s.add_dependency(%q<fixjour>, [">= 0"])
51
51
  end
52
52
  else
53
- s.add_dependency(%q<rspec>, [">= 0"])
54
- s.add_dependency(%q<cucumber>, [">= 0"])
53
+ s.add_dependency(%q<fixjour>, [">= 0"])
55
54
  end
56
55
  end
@@ -1,4 +1,19 @@
1
- Given /^a new (\S+)(.*)$/ do |model_name, args|
1
+ Given /^a new (\S+)(.*) with:$/ do |model_name, args, attr_table|
2
+ combined_args = args
3
+ attr_table.raw.each do |attr_array|
4
+ attr_name = attr_array[0]
5
+ attr_value = attr_array[1]
6
+ attr_phrase = " with #{attr_name} \"#{attr_value}\""
7
+ combined_args += attr_phrase
8
+ end
9
+ create_dynamic_instance model_name, combined_args
10
+ end
11
+
12
+ Given /^a new (\S+)(.*[^:])$/ do |model_name, args|
13
+ create_dynamic_instance model_name, args
14
+ end
15
+
16
+ def create_dynamic_instance model_name, args
2
17
  attributes = {}
3
18
  parsing_state = ""
4
19
  args.scan(/(for|with|and) ([^\"]+) "([^\"]*)"/).each do |declaration|
@@ -11,11 +26,15 @@ Given /^a new (\S+)(.*)$/ do |model_name, args|
11
26
  associated_model, lookup_attribute = key.split(' with ').map {|x| x.gsub(/ /, '_')}
12
27
  fk_name = associated_model
13
28
  klass = Address
29
+
30
+ # TODO: Pick up these aliases dynamically from the ActiveRecord declarations.
31
+ # it should not live here
14
32
  if associated_model == 'address'
15
33
  fk_name = 'shipping_address'
16
34
  else
17
35
  klass = associated_model.classify.constantize
18
36
  end
37
+
19
38
  attributes[fk_name + '_id'] = klass.first(:conditions => {lookup_attribute => value}).id
20
39
  else ; raise('unknown join word "%s"' % parsing_state)
21
40
  end
metadata CHANGED
@@ -1,29 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: featured_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - bendycode
8
+ - listrophy
9
+ - arta
10
+ - randland
8
11
  autorequire:
9
12
  bindir: bin
10
13
  cert_chain: []
11
14
 
12
- date: 2009-10-06 00:00:00 -05:00
15
+ date: 2009-10-30 00:00:00 -05:00
13
16
  default_executable:
14
17
  dependencies:
15
18
  - !ruby/object:Gem::Dependency
16
- name: rspec
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- version:
25
- - !ruby/object:Gem::Dependency
26
- name: cucumber
19
+ name: fixjour
27
20
  type: :development
28
21
  version_requirement:
29
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -41,11 +34,13 @@ extensions: []
41
34
  extra_rdoc_files:
42
35
  - LICENSE
43
36
  - README.rdoc
37
+ - README.textile
44
38
  files:
45
39
  - .document
46
40
  - .gitignore
47
41
  - LICENSE
48
42
  - README.rdoc
43
+ - README.textile
49
44
  - Rakefile
50
45
  - VERSION
51
46
  - featured_model.gemspec