cross_spec_rails 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -18
- data/app/controllers/cross_spec_rails/factories_controller.rb +22 -11
- data/lib/cross_spec_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d1f9ef42638747daf1d61f6dce14595d9d152c3
|
4
|
+
data.tar.gz: d725d3601926ad2e3e17d078e885b34f433004d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 201c7f4e80d97cc27ec1b94f31ee6840e1d88ee599745b95ebc6ec8c124a266bb30ea052f59b217bc9641714e0190e3433c32f4d1f0d4a7ad4c0691affb4e1cd
|
7
|
+
data.tar.gz: 523da1fd1c4bc4a8451f0a90dc0a0a019dac481b8c9b0ca71debd47ba9014feaf920a63bb1865d4ca4f43bebe576a5f62e8d21d6fd3d6b4179ef6c1e08c43fa8
|
data/README.md
CHANGED
@@ -1,13 +1,28 @@
|
|
1
1
|
# CrossSpecRails
|
2
|
-
|
2
|
+
Provides integrations between [cross spec ruby](https://github.com/doximity/cross_spec_ruby) and Rails.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'cross_spec_rails'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
```bash
|
13
|
+
$ bundle
|
14
|
+
```
|
3
15
|
|
4
16
|
## Usage
|
5
17
|
Mount the engine in your routes file like
|
6
18
|
```
|
7
|
-
|
19
|
+
if Rails.env.test?
|
20
|
+
mount CrossSpecRails::Engine, at: "/cross_spec"
|
21
|
+
end
|
8
22
|
```
|
9
23
|
|
10
24
|
### Requesting factory data over http
|
25
|
+
_N.B only FactoryGirl/FactoryBot are supported right now._
|
11
26
|
|
12
27
|
```
|
13
28
|
curl -X POST http://localhost:5020/cross_spec/factories/user
|
@@ -16,7 +31,7 @@ Note the URL namespace from the routes.rb of `cross_spec` followed by the `/fact
|
|
16
31
|
|
17
32
|
You can also specify attributes for the factory using a query string like
|
18
33
|
```
|
19
|
-
curl -X POST http://localhost:5020/cross_spec/factories/user?email=julie@example.com&name=Julie
|
34
|
+
curl -X POST http://localhost:5020/cross_spec/factories/user?attributes[email]=julie@example.com&attributes[name]=Julie
|
20
35
|
```
|
21
36
|
|
22
37
|
Traits are supported as well
|
@@ -24,24 +39,15 @@ Traits are supported as well
|
|
24
39
|
curl -X POST http://localhost:5020/cross_spec/factories/user?traits[]=admin&traits[]=with_articles
|
25
40
|
```
|
26
41
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
## Installation
|
31
|
-
Add this line to your application's Gemfile:
|
32
|
-
|
33
|
-
```ruby
|
34
|
-
gem 'cross_spec_rails'
|
42
|
+
You can control the response format with `to_json_args`
|
35
43
|
```
|
44
|
+
curl -X POST http://localhost:5020/cross_spec/factories/user?to_json_args[include]=articles
|
36
45
|
|
37
|
-
|
38
|
-
```bash
|
39
|
-
$ bundle
|
40
|
-
```
|
46
|
+
See the [to_json docs](https://apidock.com/rails/ActiveRecord/Serialization/to_json) for supported params. The object provided in the request is passed directly to that method
|
41
47
|
|
42
|
-
|
43
|
-
```
|
44
|
-
|
48
|
+
Finally the bulk api is also supported
|
49
|
+
```
|
50
|
+
curl -X POST http://localhost:5020/cross_spec/factories_list/user?num=4
|
45
51
|
```
|
46
52
|
|
47
53
|
## Contributing
|
@@ -17,26 +17,37 @@ module CrossSpecRails
|
|
17
17
|
skip_before_action :verify_authenticity_token
|
18
18
|
|
19
19
|
def create
|
20
|
-
factory = params[:factory]
|
21
|
-
traits = Array(params[:traits]).map(&:to_sym)
|
22
|
-
attributes = params[:attributes]&.permit!.to_h
|
23
|
-
includes = params[:includes]
|
24
20
|
instance = factory_klass.create(factory, *traits, attributes)
|
25
|
-
render json: instance.to_json(
|
21
|
+
render json: instance.to_json(to_json_args)
|
26
22
|
end
|
27
23
|
|
28
24
|
def create_list
|
29
|
-
factory = params[:factory]
|
30
|
-
traits = Array(params[:traits]).map(&:to_sym)
|
31
|
-
attributes = params[:attributes]&.permit!.to_h
|
32
|
-
includes = params[:includes]
|
33
|
-
num = params[:num].to_i
|
34
25
|
instances = factory_klass.create_list(factory, num, *traits, attributes)
|
35
|
-
render json:
|
26
|
+
render json: instances.map { |instance| instance.to_json(to_json_args) }
|
36
27
|
end
|
37
28
|
|
38
29
|
private
|
39
30
|
|
31
|
+
def factory
|
32
|
+
params[:factory]
|
33
|
+
end
|
34
|
+
|
35
|
+
def traits
|
36
|
+
Array(params[:traits]).map(&:to_sym)
|
37
|
+
end
|
38
|
+
|
39
|
+
def attributes
|
40
|
+
params[:attributes]&.permit!.to_h
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_json_args
|
44
|
+
params[:to_json_args]
|
45
|
+
end
|
46
|
+
|
47
|
+
def num
|
48
|
+
params[:num].to_i
|
49
|
+
end
|
50
|
+
|
40
51
|
def factory_klass
|
41
52
|
return FactoryBot if defined? FactoryBot
|
42
53
|
return FactoryGirl if defined? FactoryGirl
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cross_spec_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Fischer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|