cucumber_factory 2.1.0 → 2.1.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.cucumber-1.3.lock +1 -1
- data/Gemfile.cucumber-2.4.lock +1 -1
- data/Gemfile.cucumber-3.0.lock +1 -1
- data/Gemfile.cucumber-3.1.lock +1 -1
- data/lib/cucumber_factory/build_strategy.rb +1 -0
- data/lib/cucumber_factory/factory.rb +18 -8
- data/lib/cucumber_factory/version.rb +1 -1
- data/spec/cucumber_factory/steps_spec.rb +38 -0
- data/spec/support/database.rb +2 -0
- data/spec/support/factories/factories.rb +15 -1
- data/spec/support/models/movie.rb +1 -0
- data/spec/support/models/opera.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: baa05dc176d4705c737b2ad4f7257f01f0da4d0e07aae0513acc8248c7577550
|
4
|
+
data.tar.gz: 68ff25b1099b7eabb458e60e9cb95e8edb8ec7051befdd2c493353b7c23ef0f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ca06816ddcc668384556e40eef5466bb231dc9c4c458bb277f7296fd715d32e73d70af414d2e8c2cc8a9e5bd6157d59ec99c9e93ca737c5a2b015bfb1c82970
|
7
|
+
data.tar.gz: 293eabcf22252aca840ca43800d24f9e75a5a4cbf20aa6efbcfa52051782e2f3c5c6286166fc44c56decaad247972d7d487cc0fe08f7661527512ce2c80da7d9
|
data/CHANGELOG.md
CHANGED
@@ -15,6 +15,13 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
|
|
15
15
|
|
16
16
|
-
|
17
17
|
|
18
|
+
## 2.1.1 - 2020-05-20
|
19
|
+
|
20
|
+
### Compatible changes
|
21
|
+
|
22
|
+
- Cucumber 2.1.0 introduced some regressions which are being addressed with this patch:
|
23
|
+
- Fix the assignment of polymorphic associations.
|
24
|
+
- Restore the support for inherited traits within nested factories.
|
18
25
|
|
19
26
|
## 2.1.0 - 2020-03-09
|
20
27
|
|
data/Gemfile.cucumber-1.3.lock
CHANGED
data/Gemfile.cucumber-2.4.lock
CHANGED
data/Gemfile.cucumber-3.0.lock
CHANGED
data/Gemfile.cucumber-3.1.lock
CHANGED
@@ -11,6 +11,7 @@ module CucumberFactory
|
|
11
11
|
factory = factory_bot_factory(model_prose, variants)
|
12
12
|
|
13
13
|
if factory
|
14
|
+
factory.compile # Required to load inherited traits!
|
14
15
|
strategy = factory_bot_strategy(factory, model_prose, variants)
|
15
16
|
transient_attributes = factory_bot_transient_attributes(factory, variants)
|
16
17
|
else
|
@@ -146,14 +146,16 @@ module CucumberFactory
|
|
146
146
|
end
|
147
147
|
|
148
148
|
def attribute_value(world, model_class, transient_attributes, attribute, value)
|
149
|
-
association_class =
|
149
|
+
associated, association_class = resolve_association(attribute, model_class, transient_attributes)
|
150
150
|
|
151
151
|
if matches_fully?(value, VALUE_ARRAY)
|
152
152
|
elements_str = unquote(value)
|
153
153
|
value = elements_str.scan(VALUE_SCALAR).map { |v| attribute_value(world, model_class, transient_attributes, attribute, v) }
|
154
|
-
elsif
|
154
|
+
elsif associated
|
155
155
|
if matches_fully?(value, VALUE_LAST_RECORD)
|
156
|
-
|
156
|
+
raise(Error, "Cannot set last #{model_class}##{attribute} for polymorphic associations") unless association_class.present?
|
157
|
+
|
158
|
+
value = CucumberFactory::Switcher.find_last(association_class) || raise(Error, "There is no last #{attribute}")
|
157
159
|
elsif matches_fully?(value, VALUE_STRING)
|
158
160
|
value = unquote(value)
|
159
161
|
value = get_named_record(world, value) || transform_value(world, value)
|
@@ -169,17 +171,25 @@ module CucumberFactory
|
|
169
171
|
value
|
170
172
|
end
|
171
173
|
|
172
|
-
def
|
174
|
+
def resolve_association(attribute, model_class, transient_attributes)
|
173
175
|
return unless model_class.respond_to?(:reflect_on_association)
|
174
176
|
|
175
|
-
|
176
|
-
|
177
|
+
association = model_class.reflect_on_association(attribute)
|
178
|
+
association_class = nil
|
179
|
+
|
180
|
+
if association
|
181
|
+
association_class = association.klass unless association.polymorphic?
|
182
|
+
associated = true
|
177
183
|
elsif transient_attributes.include?(attribute.to_sym)
|
178
184
|
klass_name = attribute.to_s.camelize
|
179
|
-
|
185
|
+
if Object.const_defined?(klass_name)
|
186
|
+
association_class = klass_name.constantize
|
187
|
+
associated = true
|
188
|
+
end
|
180
189
|
else
|
181
|
-
|
190
|
+
associated = false
|
182
191
|
end
|
192
|
+
[associated, association_class]
|
183
193
|
end
|
184
194
|
|
185
195
|
def resolve_scalar_value(world, model_class, attribute, value)
|
@@ -356,6 +356,44 @@ title: Before Sunrise
|
|
356
356
|
prequel = Movie.find_by_title!('Before Sunrise')
|
357
357
|
movie.prequel.should == prequel
|
358
358
|
end
|
359
|
+
|
360
|
+
it 'supports named associations with polymorphic associations' do
|
361
|
+
invoke_cucumber_step('"my opera" is an opera')
|
362
|
+
invoke_cucumber_step('there is a movie with the premiere site "my opera"')
|
363
|
+
end
|
364
|
+
|
365
|
+
it 'does not support last record references with polymorphic associations as the target class cannot be guessed' do
|
366
|
+
invoke_cucumber_step('there is an opera')
|
367
|
+
expect {
|
368
|
+
invoke_cucumber_step('there is a movie with the premiere site above')
|
369
|
+
}.to raise_error(CucumberFactory::Factory::Error, 'Cannot set last Movie#premiere_site for polymorphic associations')
|
370
|
+
end
|
371
|
+
|
372
|
+
it 'works with nested factories (BUGFIX)' do
|
373
|
+
invoke_cucumber_step('there is a subgenre movie')
|
374
|
+
end
|
375
|
+
|
376
|
+
describe 'references to named records are tracked correctly' do
|
377
|
+
# CucumberFactory keeps track of all created records by their attributes.
|
378
|
+
# For example, if you create a user with the name "Peter" you can reference him later on as "Peter".
|
379
|
+
|
380
|
+
it 'does not overwrite existing references when associating new records with another reference (BUGFIX)' do
|
381
|
+
invoke_cucumber_step('"reviewer" is a user with the id "1"')
|
382
|
+
movie1 = invoke_cucumber_step('there is a movie with the reviewer "reviewer" and the id "2"') # <- should not overwrite the 'reviewer' reference
|
383
|
+
movie2 = invoke_cucumber_step('there is a movie with the reviewer "reviewer" and the id "3"')
|
384
|
+
|
385
|
+
expect(movie1.reviewer_id).to eq(1)
|
386
|
+
expect(movie2.reviewer_id).to eq(1)
|
387
|
+
end
|
388
|
+
|
389
|
+
it 'does not set new references when setting primary keys of an association (BUGFIX)' do
|
390
|
+
movie1 = invoke_cucumber_step('there is a movie with the id "123" and the user id "456"') # <- should not set a '456' reference
|
391
|
+
movie2 = invoke_cucumber_step('there is a movie with the user id "456"')
|
392
|
+
|
393
|
+
expect(movie1.reviewer_id).to eq(456)
|
394
|
+
expect(movie2.reviewer_id).to eq(456)
|
395
|
+
end
|
396
|
+
end
|
359
397
|
end
|
360
398
|
|
361
399
|
context 'without FactoryBot' do
|
data/spec/support/database.rb
CHANGED
@@ -25,7 +25,21 @@ FactoryBot.define do
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
factory :movie, :class => Movie
|
28
|
+
factory :movie, :class => Movie do
|
29
|
+
transient do
|
30
|
+
user { nil }
|
31
|
+
user_id { nil }
|
32
|
+
end
|
33
|
+
|
34
|
+
after(:build) do |movie, evaluator|
|
35
|
+
movie.reviewer = evaluator.user if evaluator.user
|
36
|
+
movie.reviewer_id = evaluator.user_id if evaluator.user_id
|
37
|
+
end
|
38
|
+
|
39
|
+
trait :parent_movie_trait
|
40
|
+
|
41
|
+
factory :subgenre_movie, traits: [:parent_movie_trait]
|
42
|
+
end
|
29
43
|
factory :opera, :class => Opera
|
30
44
|
factory :payment, :class => Payment
|
31
45
|
factory :uuid_user, :class => UuidUser
|
@@ -3,6 +3,7 @@ class Movie < ActiveRecord::Base
|
|
3
3
|
belongs_to :prequel, :class_name => "Movie"
|
4
4
|
belongs_to :reviewer, :class_name => "User"
|
5
5
|
belongs_to :uuid_reviewer, :class_name => "UuidUser"
|
6
|
+
belongs_to :premiere_site, polymorphic: true, required: false
|
6
7
|
|
7
8
|
validate do |record|
|
8
9
|
record.errors.add(:reviewer, 'may not be deleted') if record.reviewer and record.reviewer.deleted?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber_factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henning Koch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cucumber
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
- !ruby/object:Gem::Version
|
135
135
|
version: '0'
|
136
136
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
137
|
+
rubygems_version: 3.1.2
|
138
138
|
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: Create records from Cucumber features without writing step definitions.
|