resource_spec 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/resource_spec/create.rb +19 -10
- data/lib/resource_spec/destroy.rb +10 -4
- data/lib/resource_spec/shared.rb +22 -0
- data/lib/resource_spec/update.rb +19 -11
- data/lib/resource_spec/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: f24223641c435c6047cc51f7c4d0f15b5fa94ec4
|
4
|
+
data.tar.gz: 2caa858459101327e5077587ea4e6d3c3cba679a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88ee506f6398202e8d6422babc6b74c593bd46d122dac6d9acbfaa93dcd84c7cf2cb79e7efa41fb500625ebfe18b63c135ec2ed0e02ab5f148693f8cd9a58e01
|
7
|
+
data.tar.gz: d199d63ffcfb0dab3496f073472d874ea474f0f5408f61d7ba7dfc915d3ec8190c793e30dc89c282e9f3245046d14aba59fcfe7e7a22fa411b883d4c36c95c58
|
data/README.md
CHANGED
@@ -109,6 +109,24 @@ include_context "ResourceSpec", User do
|
|
109
109
|
end
|
110
110
|
```
|
111
111
|
|
112
|
+
### XHR
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
include_context "ResourceSpec", User do
|
116
|
+
it_behaves_like "POST :create", xhr: true
|
117
|
+
it_behaves_like "PUT :update", xhr: true
|
118
|
+
it_behaves_like "DELETE :destroy", xhr: true
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
### Paranoia on destroy
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
include_context "ResourceSpec", User do
|
126
|
+
it_behaves_like "DELETE :destroy", paranoid: true
|
127
|
+
end
|
128
|
+
```
|
129
|
+
|
112
130
|
## Installation
|
113
131
|
|
114
132
|
Add this line to your application's Gemfile:
|
data/lib/resource_spec/create.rb
CHANGED
@@ -1,30 +1,39 @@
|
|
1
|
-
RSpec.shared_examples "POST :create" do
|
1
|
+
RSpec.shared_examples "POST :create" do |options = {}|
|
2
2
|
describe "POST :create" do
|
3
|
-
include_examples "POST :create, success"
|
3
|
+
include_examples "POST :create, success", options
|
4
|
+
include_examples "POST :create, fail", options
|
4
5
|
end
|
5
6
|
end
|
6
7
|
|
7
|
-
RSpec.shared_examples "POST :create
|
8
|
+
RSpec.shared_examples "send POST :create" do |options = {}|
|
9
|
+
before do
|
10
|
+
if options[:xhr]
|
11
|
+
xhr :post, :create, url_args
|
12
|
+
else
|
13
|
+
post :create, url_args
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.shared_examples "POST :create, success" do |options = {}|
|
8
19
|
context "success" do
|
9
20
|
let(:url_args) { create_url_args }
|
10
21
|
let(:redirect_url) { success_create_url }
|
11
22
|
|
12
|
-
|
13
|
-
|
14
|
-
include_examples "responds 301"
|
23
|
+
include_examples "send POST :create", options
|
24
|
+
include_examples "responds with success", options
|
15
25
|
include_examples "resource has no errors"
|
16
26
|
include_examples "resource persisted"
|
17
27
|
include_examples "resource has expected attributes"
|
18
28
|
end
|
19
29
|
end
|
20
30
|
|
21
|
-
RSpec.shared_examples "POST :create, fail" do
|
31
|
+
RSpec.shared_examples "POST :create, fail" do |options = {}|
|
22
32
|
context "fail" do
|
23
33
|
let(:url_args) { invalid_create_url_args }
|
24
34
|
|
25
|
-
|
26
|
-
|
27
|
-
include_examples "responds 200"
|
35
|
+
include_examples "send POST :create", options
|
36
|
+
include_examples "responds with failure", options
|
28
37
|
include_examples "resource has errors"
|
29
38
|
end
|
30
39
|
end
|
@@ -1,15 +1,21 @@
|
|
1
|
-
RSpec.shared_examples "DELETE :destroy" do
|
1
|
+
RSpec.shared_examples "DELETE :destroy" do |options = {}|
|
2
2
|
describe "DELETE :destroy" do
|
3
3
|
context "success" do
|
4
4
|
let(:url_args) { destroy_url_args }
|
5
5
|
let(:redirect_url) { success_destroy_url }
|
6
6
|
|
7
|
-
before
|
7
|
+
before do
|
8
|
+
if options[:xhr]
|
9
|
+
xhr :delete, :destroy, url_args
|
10
|
+
else
|
11
|
+
delete :destroy, url_args
|
12
|
+
end
|
13
|
+
end
|
8
14
|
|
9
|
-
include_examples "responds
|
15
|
+
include_examples "responds with success", options
|
10
16
|
|
11
17
|
it "resource destroyed" do
|
12
|
-
if
|
18
|
+
if options[:paranoid]
|
13
19
|
expect(resource.deleted_at).to be_present
|
14
20
|
else
|
15
21
|
expect { resource.reload }.to raise_error(
|
data/lib/resource_spec/shared.rb
CHANGED
@@ -10,6 +10,28 @@ RSpec.shared_examples "responds 301" do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
RSpec.shared_examples "responds with success" do |options = {}|
|
14
|
+
if options[:xhr]
|
15
|
+
include_examples "responds 200"
|
16
|
+
else
|
17
|
+
include_examples "responds 301"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
RSpec.shared_examples "responds with failure" do |options = {}|
|
22
|
+
if options[:xhr]
|
23
|
+
include_examples "responds 422"
|
24
|
+
else
|
25
|
+
include_examples "responds 200"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
RSpec.shared_examples "responds 422" do
|
30
|
+
it "responds 422" do
|
31
|
+
expect(response).to be_unprocessable
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
13
35
|
RSpec.shared_examples "resource has no errors" do
|
14
36
|
it "resource has no errors" do
|
15
37
|
expect(resource.errors).to be_blank, "Given params: #{url_args} failed with errors: #{resource.errors.full_messages}"
|
data/lib/resource_spec/update.rb
CHANGED
@@ -1,30 +1,38 @@
|
|
1
|
-
RSpec.shared_examples "PUT :update" do
|
1
|
+
RSpec.shared_examples "PUT :update" do |options = {}|
|
2
2
|
describe "PUT :update" do
|
3
|
-
include_examples "PUT :update, success"
|
4
|
-
include_examples "PUT :update, fail"
|
3
|
+
include_examples "PUT :update, success", options
|
4
|
+
include_examples "PUT :update, fail", options
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
RSpec.shared_examples "PUT :update
|
8
|
+
RSpec.shared_examples "send PUT :update" do |options = {}|
|
9
|
+
before do
|
10
|
+
if options[:xhr]
|
11
|
+
xhr :put, :update, url_args
|
12
|
+
else
|
13
|
+
put :update, url_args
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec.shared_examples "PUT :update, success" do |options = {}|
|
9
19
|
context "success" do
|
10
20
|
let(:url_args) { update_url_args }
|
11
21
|
let(:redirect_url) { success_update_url }
|
12
22
|
|
13
|
-
|
14
|
-
|
15
|
-
include_examples "responds 301"
|
23
|
+
include_examples "send PUT :update", options
|
24
|
+
include_examples "responds with success", options
|
16
25
|
include_examples "resource has no errors"
|
17
26
|
include_examples "resource has expected attributes"
|
18
27
|
end
|
19
28
|
end
|
20
29
|
|
21
|
-
RSpec.shared_examples "PUT :update, fail" do
|
30
|
+
RSpec.shared_examples "PUT :update, fail" do |options = {}|
|
22
31
|
context "fail" do
|
23
32
|
let(:url_args) { invalid_update_url_args }
|
24
33
|
|
25
|
-
|
26
|
-
|
27
|
-
include_examples "responds 200"
|
34
|
+
include_examples "send PUT :update", options
|
35
|
+
include_examples "responds with failure", options
|
28
36
|
include_examples "resource has errors"
|
29
37
|
end
|
30
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resource_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Victor Sokolov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|