cypress-on-rails 1.12.0 → 1.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +1 -11
- data/docs/factory_bot_associations.md +109 -0
- data/lib/cypress_on_rails/smart_factory_wrapper.rb +7 -4
- data/lib/cypress_on_rails/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32a416c65647445473bce7bcf306bda04eafb673d8d4af20c795f13692f4da8e
|
4
|
+
data.tar.gz: ee456e7396cfa0d94cc9cd80d0a54dc6c89248254c3855b66578f8e214a0982d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4022aeb303bf3fa6514cd2b221869bb531e7e0be1b85de8f35ba20f6e5d2ff9fc8062ab2560a7d71d17ce0931719c3e57a33b23b25e3fa3ddb60a02de579c527
|
7
|
+
data.tar.gz: 18d9b6423eb5fafbf2bf756de4b9e72fc8a5dc8b0240a15a1598e97f16acac6e589ff591493158ced0779374a27a347525c75eb4b4d1b9b2dd16364276afd10d
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [1.12.1]
|
2
|
+
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.12.0...v1.12.1
|
3
|
+
|
4
|
+
### Tasks
|
5
|
+
* Documenting how to setup Factory Associations [PR 100](https://github.com/shakacode/cypress-on-rails/pull/100)
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
* keep track of factory manual reloads to prevent auto_reload from reloading again [PR 98](https://github.com/shakacode/cypress-on-rails/pull/98)
|
9
|
+
|
1
10
|
## [1.12.0]
|
2
11
|
[Compare]: https://github.com/shakacode/cypress-on-rails/compare/v1.11.0...v1.12.0
|
3
12
|
|
data/README.md
CHANGED
@@ -132,17 +132,6 @@ node_modules/.bin/cypress run
|
|
132
132
|
|
133
133
|
You can run your [factory_bot](https://github.com/thoughtbot/factory_bot) directly as well
|
134
134
|
|
135
|
-
```ruby
|
136
|
-
# spec/cypress/app_commands/factory_bot.rb
|
137
|
-
require 'cypress_on_rails/smart_factory_wrapper'
|
138
|
-
|
139
|
-
CypressOnRails::SmartFactoryWrapper.configure(
|
140
|
-
always_reload: !Rails.configuration.cache_classes,
|
141
|
-
factory: FactoryBot,
|
142
|
-
files: Dir['./spec/factories/**/*.rb']
|
143
|
-
)
|
144
|
-
```
|
145
|
-
|
146
135
|
```js
|
147
136
|
// spec/cypress/integrations/simple_spec.js
|
148
137
|
describe('My First Test', function() {
|
@@ -166,6 +155,7 @@ describe('My First Test', function() {
|
|
166
155
|
})
|
167
156
|
})
|
168
157
|
```
|
158
|
+
You can check the [association Docs](https://github.com/shakacode/cypress-on-rails/blob/master/docs/factory_bot_associations.md) on more ways to setup association with the correct data.
|
169
159
|
|
170
160
|
In some cases, using static Cypress fixtures may not provide sufficient flexibility when mocking HTTP response bodies - it's possible to use `FactoryBot.build` to generate Ruby hashes that can then be used as mock JSON responses:
|
171
161
|
```ruby
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Setting up associations with the correct data
|
2
|
+
|
3
|
+
You cannot access associations directly from Cypress like you can do with ruby tests.
|
4
|
+
So setting up associations has to be done differently from within Cypress.
|
5
|
+
|
6
|
+
There are a few ways you can setup associations with the correct data using Cypress and FactoryBot.
|
7
|
+
1. Setting the foreign keys
|
8
|
+
2. Using transient attributes
|
9
|
+
3. Using Nested Attributes
|
10
|
+
4. Combination of the above depending on your situation
|
11
|
+
|
12
|
+
Assuming you have the following models
|
13
|
+
|
14
|
+
```rb
|
15
|
+
class Post < ApplicationRecord
|
16
|
+
belongs_to :author
|
17
|
+
accepts_nested_attributes_for :author
|
18
|
+
end
|
19
|
+
|
20
|
+
class Author < ApplicationRecord
|
21
|
+
has_many :posts
|
22
|
+
accepts_nested_attributes_for :posts
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
You can do the following:
|
27
|
+
|
28
|
+
## 1. Setting the foreign keys
|
29
|
+
|
30
|
+
factories.rb
|
31
|
+
```rb
|
32
|
+
FactoryBot.define do
|
33
|
+
factory :author do
|
34
|
+
name { 'Taylor' }
|
35
|
+
end
|
36
|
+
|
37
|
+
factory :post do
|
38
|
+
title { 'Cypress on Rails is Awesome' }
|
39
|
+
author_id { create(:author).id }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
then in Cypress
|
45
|
+
```js
|
46
|
+
// example with overriding the defaults
|
47
|
+
cy.appFactories([['create', 'author', { name: 'James' }]]).then((records) => {
|
48
|
+
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_id: records[0].id }]]
|
49
|
+
});
|
50
|
+
|
51
|
+
// example without overriding anything
|
52
|
+
cy.appFactories([['create', 'author']]).then((records) => {
|
53
|
+
cy.appFactories([['create', 'post', { author_id: records[0].id }]]
|
54
|
+
});
|
55
|
+
```
|
56
|
+
|
57
|
+
## 2. Using transient attributes
|
58
|
+
|
59
|
+
```rb
|
60
|
+
FactoryBot.define do
|
61
|
+
factory :author do
|
62
|
+
name { 'Taylor' }
|
63
|
+
end
|
64
|
+
|
65
|
+
factory :post do
|
66
|
+
transient do
|
67
|
+
author_name { 'Taylor' }
|
68
|
+
end
|
69
|
+
title { 'Cypress on Rails is Awesome' }
|
70
|
+
author { create(:author, name: author_name ) }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
then in Cypress
|
76
|
+
```js
|
77
|
+
// example with overriding the defaults
|
78
|
+
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_name: 'James' }]]
|
79
|
+
|
80
|
+
// example without overriding
|
81
|
+
cy.appFactories([['create', 'post']]
|
82
|
+
```
|
83
|
+
|
84
|
+
## 3. Using Nested Attributes
|
85
|
+
|
86
|
+
```rb
|
87
|
+
FactoryBot.define do
|
88
|
+
factory :author do
|
89
|
+
name { 'Taylor' }
|
90
|
+
end
|
91
|
+
|
92
|
+
factory :post do
|
93
|
+
title { 'Cypress on Rails is Awesome' }
|
94
|
+
author_attributes { { name: 'Taylor' } }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
99
|
+
then in Cypress
|
100
|
+
```js
|
101
|
+
// example with overriding the defaults
|
102
|
+
cy.appFactories([['create', 'post', { title: 'Cypress is cool', author_attributes: { name: 'James' } }]]
|
103
|
+
|
104
|
+
// example without overriding
|
105
|
+
cy.appFactories([['create', 'post']]
|
106
|
+
|
107
|
+
// example of creating author with multiple posts
|
108
|
+
cy.appFactories([['create', 'author', { name: 'James', posts_attributes: [{ name: 'Cypress is cool' }, {name: 'Rails is awesome' }] ]]
|
109
|
+
```
|
@@ -80,6 +80,7 @@ module CypressOnRails
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def reload
|
83
|
+
@latest_mtime = current_latest_mtime
|
83
84
|
logger.info 'Loading Factories'
|
84
85
|
factory.reload
|
85
86
|
files.each do |file|
|
@@ -105,14 +106,16 @@ module CypressOnRails
|
|
105
106
|
CypressOnRails.configuration.logger
|
106
107
|
end
|
107
108
|
|
109
|
+
def current_latest_mtime
|
110
|
+
files.map{|file| @file_system.mtime(file) }.max
|
111
|
+
end
|
112
|
+
|
108
113
|
def auto_reload
|
109
|
-
|
110
|
-
return unless should_reload?(current_latest_mtime)
|
111
|
-
@latest_mtime = current_latest_mtime
|
114
|
+
return unless should_reload?
|
112
115
|
reload
|
113
116
|
end
|
114
117
|
|
115
|
-
def should_reload?
|
118
|
+
def should_reload?
|
116
119
|
@always_reload || @latest_mtime.nil? || @latest_mtime < current_latest_mtime
|
117
120
|
end
|
118
121
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cypress-on-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.12.
|
4
|
+
version: 1.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- miceportal team
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-01-
|
12
|
+
date: 2022-01-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- Rakefile
|
101
101
|
- cypress-on-rails.gemspec
|
102
102
|
- docs/authentication.md
|
103
|
+
- docs/factory_bot_associations.md
|
103
104
|
- lib/cypress-on-rails.rb
|
104
105
|
- lib/cypress/smart_factory_wrapper.rb
|
105
106
|
- lib/cypress_dev.rb
|