mattscilipoti-model_steps 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +87 -1
- data/Rakefile +2 -1
- data/VERSION +1 -1
- data/lib/model_steps/step_definitions.rb +12 -12
- data/mattscilipoti-model_steps.gemspec +64 -0
- metadata +25 -8
data/README.rdoc
CHANGED
@@ -1,7 +1,93 @@
|
|
1
1
|
= mattscilipoti-model_steps
|
2
2
|
|
3
|
-
Description goes here.
|
4
3
|
|
4
|
+
|
5
|
+
Attempt to answer 4 needs:
|
6
|
+
1. Support creation of models with attributes
|
7
|
+
2. Uniquely identify models in cucumber steps
|
8
|
+
3. Reference associated models
|
9
|
+
4. Support factory derivations i.e. user_admin, user_manager
|
10
|
+
|
11
|
+
Attempt:
|
12
|
+
|
13
|
+
|
14
|
+
Assume:
|
15
|
+
User belongs_to Organization
|
16
|
+
User has_many Courses
|
17
|
+
Course belongs_to Topic
|
18
|
+
User has_friendly_id :login
|
19
|
+
|
20
|
+
Note: it is dependent on friendly_id: http://github.com/norman/friendly_id
|
21
|
+
|
22
|
+
General: a step that ends in colon (:) expects a cucumber table.
|
23
|
+
|
24
|
+
|
25
|
+
1. Support creation of models with attributes
|
26
|
+
Given these Users exist:
|
27
|
+
|login |first_name |last_name |
|
28
|
+
|tester |joe |tester |
|
29
|
+
|anon |John |Doe |
|
30
|
+
* only one row is required. Works the same for one, or more, rows.
|
31
|
+
|
32
|
+
This will call:
|
33
|
+
Factory(:user, :login => 'tester', :first_name => 'joe', :last_name => 'tester')
|
34
|
+
Factory(:user, :login => 'anon', :first_name => 'John', :last_name => 'Doe')
|
35
|
+
|
36
|
+
Comparison:
|
37
|
+
pickle:
|
38
|
+
Single:
|
39
|
+
Given a user exists with login: "tester", first_name: "joe", last_name: "tester"
|
40
|
+
|
41
|
+
Multiple:
|
42
|
+
Given the following Users exist
|
43
|
+
|login |first_name |last_name |
|
44
|
+
|tester |joe |tester |
|
45
|
+
|anon |John |Doe |
|
46
|
+
|
47
|
+
factory_girl:
|
48
|
+
Given
|
49
|
+
|
50
|
+
|
51
|
+
1. Uniquely identify models in cucumber steps
|
52
|
+
Model:friendly_id
|
53
|
+
User:Matt
|
54
|
+
|
55
|
+
Possible options:
|
56
|
+
User:"Matt"
|
57
|
+
User|matt
|
58
|
+
|
59
|
+
2. Reference associated models
|
60
|
+
A. utilize associations in tables
|
61
|
+
Given these people exist:
|
62
|
+
|name |organization |
|
63
|
+
|Matt |Dept. A|
|
64
|
+
|
65
|
+
This will identify that 'role' is an association and perform the equivalent of:
|
66
|
+
Role.find_by_name('Admin') || Factory(:role, :name => 'Admin') #using Factory(:role, Topic.friendly_column_name => 'Admin')
|
67
|
+
|
68
|
+
B. ModelA has many ModelBs
|
69
|
+
Given User:Matt has these Courses:
|
70
|
+
|name |topic |
|
71
|
+
|B101 |Biology |
|
72
|
+
|CS101 |CompSci |
|
73
|
+
|
74
|
+
Executes:
|
75
|
+
Factory(:user, :course => :name => 'B101', :topic => Topic.find('Biology') || Factory(:topic, Topic.friendly_column_name => 'biology'))
|
76
|
+
Factory(:user, :course => :name => 'CS101', :topic => Topic.find('CompSci'))
|
77
|
+
|
78
|
+
3. Support factory derivations i.e. user_admin, user_manager
|
79
|
+
Given this User(Admin) exists:
|
80
|
+
|first_name |
|
81
|
+
|Jane |
|
82
|
+
|
83
|
+
Executes:
|
84
|
+
Factory(:user_admin, :name => 'Jane')
|
85
|
+
|
86
|
+
Given a User(with associations) exists
|
87
|
+
|
88
|
+
Executes:
|
89
|
+
Factory(:user_with_associations)
|
90
|
+
|
5
91
|
== Note on Patches/Pull Requests
|
6
92
|
|
7
93
|
* Fork the project.
|
data/Rakefile
CHANGED
@@ -9,7 +9,8 @@ begin
|
|
9
9
|
gem.description = %Q{Step Definitions for cucumber which support ActiveRecord Models}
|
10
10
|
gem.email = "matt@scilipoti.name"
|
11
11
|
gem.homepage = "http://github.com/mattscilipoti/mattscilipoti-model_steps"
|
12
|
-
gem.authors = ["Matt Scilipoti"]
|
12
|
+
gem.authors = ["Matt Scilipoti", "Chris Cahoon"]
|
13
|
+
gem.add_runtime_dependency "friendly_id", '> 3.0'
|
13
14
|
gem.add_development_dependency "micronaut"
|
14
15
|
gem.add_development_dependency "cucumber"
|
15
16
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Cucumber::Ast::Table.class_eval do
|
2
2
|
def is_date_column?(column_name)
|
3
|
-
column_name
|
3
|
+
column_name =~ /( at|_at|time|date)$/i
|
4
4
|
end
|
5
5
|
|
6
6
|
def chronic_parsable_columns
|
@@ -100,7 +100,7 @@ end
|
|
100
100
|
# Create a new ModelA with default_identifier_column = default_identifier
|
101
101
|
Given /^(.+):(.+) exists$/ do |requested_model, default_identifier|
|
102
102
|
model = requested_model_to_model(requested_model)
|
103
|
-
column_name = model.
|
103
|
+
column_name = model.friendly_id_config.column
|
104
104
|
Factory.create(model_to_factory_symbol(requested_model), column_name => default_identifier)
|
105
105
|
end
|
106
106
|
|
@@ -129,7 +129,7 @@ Given /^(\D+):(.+) has (\D+):(.+)$/ do |requested_model, default_identifier, ass
|
|
129
129
|
model_under_test = requested_model_with_identifier_to_model_instance(requested_model, default_identifier)
|
130
130
|
associated_model = requested_model_to_model(association_model_name)
|
131
131
|
factory_name = model_to_factory_symbol(associated_model)
|
132
|
-
associated_model_under_test = associated_model.
|
132
|
+
associated_model_under_test = associated_model.find(default_identifier) || Factory(factory_name, associated_model.friendly_id_config.column => default_identifier)
|
133
133
|
|
134
134
|
possible_associations = [association_model_name.underscore, association_model_name.pluralize.underscore]
|
135
135
|
association_name = possible_associations.detect {|association_name| model_under_test.respond_to?(association_name)}
|
@@ -232,7 +232,7 @@ end
|
|
232
232
|
Given /^(\D+):(.+) does not exist$/ do |requested_model, default_identifier|
|
233
233
|
begin
|
234
234
|
model = requested_model_to_model(requested_model)
|
235
|
-
instance = model.
|
235
|
+
instance = model.find(default_identifier)
|
236
236
|
if instance
|
237
237
|
instance.destroy if instance
|
238
238
|
instance.reload.should be_nil
|
@@ -307,7 +307,7 @@ When /^we setup the following:$/ do |table|
|
|
307
307
|
|
308
308
|
factory_name = model_to_factory_symbol(header)
|
309
309
|
model_klass = header.classify.constantize
|
310
|
-
new_model = model_klass.
|
310
|
+
new_model = model_klass.find(value)
|
311
311
|
|
312
312
|
new_model_params = {}
|
313
313
|
if previous_model
|
@@ -325,7 +325,7 @@ When /^we setup the following:$/ do |table|
|
|
325
325
|
if new_model
|
326
326
|
new_model.update_attributes! new_model_params
|
327
327
|
else
|
328
|
-
new_model_params.merge!({ model_klass.
|
328
|
+
new_model_params.merge!({ model_klass.friendly_id_config.column => value })
|
329
329
|
new_model = Factory.create(factory_name, new_model_params)
|
330
330
|
end
|
331
331
|
|
@@ -458,7 +458,7 @@ def assert_models(expected_models, table, should_not = false)
|
|
458
458
|
requested_params.each do |attribute_name, expected_value|
|
459
459
|
actual = model_under_test.send(attribute_name)
|
460
460
|
if actual.is_a?(ActiveRecord::Base)
|
461
|
-
actual = actual.send(actual.class.
|
461
|
+
actual = actual.send(actual.class.friendly_id_config.column)
|
462
462
|
end
|
463
463
|
if should_not
|
464
464
|
err_msg = "Expected ##{attribute_name} for '#{model_klass.name}:#{default_identifier}'\n\t to NOT have: '#{expected_value}'\n\tbut was: '#{actual}'\n * Expectations: #{requested_params.inspect} \n * #{model_klass.name}:#{default_identifier}: #{model_under_test.inspect}.\n\n"
|
@@ -475,11 +475,11 @@ end
|
|
475
475
|
|
476
476
|
def requested_model_with_identifier_to_model_instance(requested_model, default_identifier)
|
477
477
|
model = requested_model_to_model(requested_model)
|
478
|
-
model_under_test = model.
|
478
|
+
model_under_test = model.find(default_identifier)
|
479
479
|
return model_under_test
|
480
480
|
rescue ActiveRecord::RecordNotFound
|
481
481
|
factory_name = model_to_factory_symbol(requested_model)
|
482
|
-
Factory.create(factory_name, model.
|
482
|
+
Factory.create(factory_name, model.friendly_id_config.column => default_identifier)
|
483
483
|
end
|
484
484
|
|
485
485
|
def assign_requested_model_associations(model_under_test, association_quantity, requested_association_name, array_of_requested_params = [])
|
@@ -497,7 +497,7 @@ def assign_requested_model_associations(model_under_test, association_quantity,
|
|
497
497
|
existing_objects = array_of_requested_params.collect do |conditions|
|
498
498
|
if conditions.keys.first == 'default_identifier'
|
499
499
|
#for CameraEvent find by (ImportFile).name
|
500
|
-
association_model.
|
500
|
+
association_model.find(conditions.values.first)
|
501
501
|
else
|
502
502
|
association_model.find(:first, :conditions => conditions)
|
503
503
|
end
|
@@ -682,7 +682,7 @@ end
|
|
682
682
|
|
683
683
|
|
684
684
|
def perform_activity(model, default_identifier, requested_activity)
|
685
|
-
model_under_test = model.
|
685
|
+
model_under_test = model.find(default_identifier)
|
686
686
|
activity = model_under_test.send("do#{requested_activity.singularize}".underscore)
|
687
687
|
end
|
688
688
|
|
@@ -727,7 +727,7 @@ def requested_params_to_model_params(requested_params, model)
|
|
727
727
|
default_identifier = value
|
728
728
|
end
|
729
729
|
|
730
|
-
associated_model = associated_model_class_name.constantize.
|
730
|
+
associated_model = associated_model_class_name.constantize.find(default_identifier)
|
731
731
|
|
732
732
|
# TODO handle multiple associations
|
733
733
|
if /s$/ =~ association_name
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mattscilipoti-model_steps}
|
8
|
+
s.version = "0.3.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Matt Scilipoti", "Chris Cahoon"]
|
12
|
+
s.date = %q{2010-07-29}
|
13
|
+
s.description = %q{Step Definitions for cucumber which support ActiveRecord Models}
|
14
|
+
s.email = %q{matt@scilipoti.name}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"examples/example_helper.rb",
|
27
|
+
"examples/mattscilipoti-model_steps_example.rb",
|
28
|
+
"features/mattscilipoti-model_steps.feature",
|
29
|
+
"features/step_definitions/mattscilipoti-model_steps_steps.rb",
|
30
|
+
"features/support/env.rb",
|
31
|
+
"lib/mattscilipoti-model_steps.rb",
|
32
|
+
"lib/model_steps/step_definitions.rb",
|
33
|
+
"mattscilipoti-model_steps.gemspec"
|
34
|
+
]
|
35
|
+
s.homepage = %q{http://github.com/mattscilipoti/mattscilipoti-model_steps}
|
36
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.3.7}
|
39
|
+
s.summary = %q{Model Steps for cucumber}
|
40
|
+
s.test_files = [
|
41
|
+
"examples/example_helper.rb",
|
42
|
+
"examples/mattscilipoti-model_steps_example.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<friendly_id>, ["> 3.0"])
|
51
|
+
s.add_development_dependency(%q<micronaut>, [">= 0"])
|
52
|
+
s.add_development_dependency(%q<cucumber>, [">= 0"])
|
53
|
+
else
|
54
|
+
s.add_dependency(%q<friendly_id>, ["> 3.0"])
|
55
|
+
s.add_dependency(%q<micronaut>, [">= 0"])
|
56
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<friendly_id>, ["> 3.0"])
|
60
|
+
s.add_dependency(%q<micronaut>, [">= 0"])
|
61
|
+
s.add_dependency(%q<cucumber>, [">= 0"])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
metadata
CHANGED
@@ -5,23 +5,39 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Scilipoti
|
14
|
+
- Chris Cahoon
|
14
15
|
autorequire:
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-
|
19
|
+
date: 2010-07-29 00:00:00 -04:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
23
|
+
name: friendly_id
|
23
24
|
prerelease: false
|
24
25
|
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">"
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 7
|
31
|
+
segments:
|
32
|
+
- 3
|
33
|
+
- 0
|
34
|
+
version: "3.0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: micronaut
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
25
41
|
none: false
|
26
42
|
requirements:
|
27
43
|
- - ">="
|
@@ -31,11 +47,11 @@ dependencies:
|
|
31
47
|
- 0
|
32
48
|
version: "0"
|
33
49
|
type: :development
|
34
|
-
version_requirements: *
|
50
|
+
version_requirements: *id002
|
35
51
|
- !ruby/object:Gem::Dependency
|
36
52
|
name: cucumber
|
37
53
|
prerelease: false
|
38
|
-
requirement: &
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
39
55
|
none: false
|
40
56
|
requirements:
|
41
57
|
- - ">="
|
@@ -45,7 +61,7 @@ dependencies:
|
|
45
61
|
- 0
|
46
62
|
version: "0"
|
47
63
|
type: :development
|
48
|
-
version_requirements: *
|
64
|
+
version_requirements: *id003
|
49
65
|
description: Step Definitions for cucumber which support ActiveRecord Models
|
50
66
|
email: matt@scilipoti.name
|
51
67
|
executables: []
|
@@ -69,6 +85,7 @@ files:
|
|
69
85
|
- features/support/env.rb
|
70
86
|
- lib/mattscilipoti-model_steps.rb
|
71
87
|
- lib/model_steps/step_definitions.rb
|
88
|
+
- mattscilipoti-model_steps.gemspec
|
72
89
|
has_rdoc: true
|
73
90
|
homepage: http://github.com/mattscilipoti/mattscilipoti-model_steps
|
74
91
|
licenses: []
|