rspec-behaves-like-crud 0.0.1 → 0.0.2
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/README.rdoc +1 -1
- data/lib/rspec_behaves_like_crud/version.rb +1 -1
- data/lib/spec/support/mixins/incrudable.rb +8 -3
- data/lib/spec/support/shared_examples/crud_create_spec.rb +3 -3
- data/lib/spec/support/shared_examples/crud_delete_spec.rb +2 -2
- data/lib/spec/support/shared_examples/crud_edit_spec.rb +1 -1
- data/lib/spec/support/shared_examples/crud_index_spec.rb +1 -1
- data/lib/spec/support/shared_examples/crud_new_spec.rb +6 -0
- data/lib/spec/support/shared_examples/crud_show_spec.rb +1 -1
- data/lib/spec/support/shared_examples/crud_update_spec.rb +9 -9
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1839f05af8e32266fc7d1f37f28d359acfa4d8b1
|
4
|
+
data.tar.gz: 8babf4bd26491a91a22e523f8f2e3c83ab533490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b0006326a85894b29ab7e6c596416ab334416e077ce1e14e3c61023bd927c99083b786582288d6ee34cd4b60bc7e20dfc79e9f93189c03095a0c95abf0495ea
|
7
|
+
data.tar.gz: 79dfbf34c0da04df556c9bbdd8981757360c6942112f608e27c93fd1ac7b4801bdc5f0e5ee2d0046751692de779b4672d44d7fd8b8086dc682e1384d518a7224
|
data/README.rdoc
CHANGED
@@ -1,11 +1,16 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'active_support/core_ext'
|
3
|
+
|
1
4
|
module Incrudable
|
2
5
|
extend ActiveSupport::Concern
|
3
6
|
|
4
7
|
included do
|
5
8
|
let(:resource_name) { resource_class.to_s.titlecase }
|
6
|
-
let(:param_key) { resource_class.to_s.
|
9
|
+
let(:param_key) { resource_class.to_s.underscore }
|
10
|
+
|
11
|
+
let(:resource_method) { resource_class.to_s.underscore }
|
12
|
+
let(:collection_method) { resource_class.to_s.underscore.pluralize }
|
7
13
|
|
8
|
-
let(:
|
9
|
-
let(:collection_method) { resource_class.to_s.downcase.pluralize }
|
14
|
+
let(:clean_attributes) { valid_attributes.except('id') }
|
10
15
|
end
|
11
16
|
end
|
@@ -3,18 +3,18 @@ shared_examples 'a CRUD create' do
|
|
3
3
|
describe 'with valid params' do
|
4
4
|
it 'creates a new resource' do
|
5
5
|
expect do
|
6
|
-
post :create, { param_key =>
|
6
|
+
post :create, { param_key => clean_attributes }
|
7
7
|
end.to change(resource_class, :count).by(1)
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'exposes a newly created resource' do
|
11
|
-
post :create, { param_key =>
|
11
|
+
post :create, { param_key => clean_attributes }
|
12
12
|
controller.send(resource_method).should be_a(resource_class)
|
13
13
|
controller.send(resource_method).should be_persisted
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'redirects to the created resource' do
|
17
|
-
post :create, { param_key =>
|
17
|
+
post :create, { param_key => clean_attributes }
|
18
18
|
response.should redirect_to(resource_class.last)
|
19
19
|
end
|
20
20
|
end
|
@@ -2,14 +2,14 @@ shared_examples 'a CRUD delete' do
|
|
2
2
|
|
3
3
|
describe 'DELETE destroy' do
|
4
4
|
it 'destroys the requested resource' do
|
5
|
-
resource = resource_class.create!
|
5
|
+
resource = resource_class.create! clean_attributes
|
6
6
|
expect do
|
7
7
|
delete :destroy, { id: resource.to_param }
|
8
8
|
end.to change(resource_class, :count).by(-1)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'redirects to the list' do
|
12
|
-
resource = resource_class.create!
|
12
|
+
resource = resource_class.create! clean_attributes
|
13
13
|
delete :destroy, { id: resource.to_param }
|
14
14
|
response.should redirect_to(send("#{resource_class.to_s.tableize}_url"))
|
15
15
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
shared_examples 'a CRUD edit' do
|
2
2
|
describe 'GET edit' do
|
3
3
|
it 'exposes the requested resource' do
|
4
|
-
resource = resource_class.create!
|
4
|
+
resource = resource_class.create! clean_attributes
|
5
5
|
get :edit, { id: resource.to_param }
|
6
6
|
controller.send(resource_method).should eq(resource)
|
7
7
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
shared_examples 'a CRUD index' do
|
2
2
|
describe 'GET index' do
|
3
3
|
it 'exposes all resources' do
|
4
|
-
resource = resource_class.create!
|
4
|
+
resource = resource_class.create! clean_attributes
|
5
5
|
get :index, {}
|
6
6
|
controller.send(collection_method).should eq([resource])
|
7
7
|
end
|
@@ -4,5 +4,11 @@ shared_examples 'a CRUD new' do
|
|
4
4
|
get :new, {}
|
5
5
|
controller.send(resource_method).should be_a_new(resource_class)
|
6
6
|
end
|
7
|
+
|
8
|
+
it "renders 'new' template" do
|
9
|
+
get :new, {}
|
10
|
+
expect(response.status).to eq(200)
|
11
|
+
expect(response).to render_template('new')
|
12
|
+
end
|
7
13
|
end
|
8
14
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
shared_examples 'a CRUD show' do
|
2
2
|
describe 'GET show' do
|
3
3
|
it 'exposes the requested resource' do
|
4
|
-
resource = resource_class.create!
|
4
|
+
resource = resource_class.create! clean_attributes
|
5
5
|
get :show, { id: resource.to_param }
|
6
6
|
controller.send(resource_method).should eq(resource)
|
7
7
|
end
|
@@ -2,35 +2,35 @@ shared_examples 'a CRUD update' do
|
|
2
2
|
describe 'PUT update' do
|
3
3
|
describe 'with valid params' do
|
4
4
|
it 'updates the requested resource' do
|
5
|
-
resource = resource_class.create!
|
5
|
+
resource = resource_class.create! clean_attributes
|
6
6
|
resource_class.any_instance.should_receive(:save)
|
7
|
-
put :update, { id: resource.to_param, param_key =>
|
8
|
-
controller.send(resource_method).attributes.should include(
|
7
|
+
put :update, { id: resource.to_param, param_key => clean_attributes }
|
8
|
+
controller.send(resource_method).attributes.should include(clean_attributes.stringify_keys)
|
9
9
|
end
|
10
10
|
|
11
11
|
it 'exposes the requested resource' do
|
12
|
-
resource = resource_class.create!
|
13
|
-
put :update, { id: resource.to_param, param_key =>
|
12
|
+
resource = resource_class.create! clean_attributes
|
13
|
+
put :update, { id: resource.to_param, param_key => clean_attributes }
|
14
14
|
controller.send(resource_method).should eq(resource)
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'redirects to the resource' do
|
18
|
-
resource = resource_class.create!
|
19
|
-
put :update, { id: resource.to_param, param_key =>
|
18
|
+
resource = resource_class.create! clean_attributes
|
19
|
+
put :update, { id: resource.to_param, param_key => clean_attributes }
|
20
20
|
response.should redirect_to(resource)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe 'with invalid params' do
|
25
25
|
it 'assigns the resource' do
|
26
|
-
resource = resource_class.create!
|
26
|
+
resource = resource_class.create! clean_attributes
|
27
27
|
resource_class.any_instance.stub(:save).and_return(false)
|
28
28
|
put :update, { id: resource.to_param, param_key => invalid_attributes }
|
29
29
|
controller.send(resource_method).should eq(resource)
|
30
30
|
end
|
31
31
|
|
32
32
|
it "re-renders the 'edit' template" do
|
33
|
-
resource = resource_class.create!
|
33
|
+
resource = resource_class.create! clean_attributes
|
34
34
|
resource_class.any_instance.stub(:save).and_return(false)
|
35
35
|
put :update, { id: resource.to_param, param_key => invalid_attributes }
|
36
36
|
response.should render_template('edit')
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-behaves-like-crud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Simon
|
8
|
+
- Maciej Tomaka
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-13 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rails
|
@@ -65,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
66
|
version: '0'
|
66
67
|
requirements: []
|
67
68
|
rubyforge_project:
|
68
|
-
rubygems_version: 2.
|
69
|
+
rubygems_version: 2.1.1
|
69
70
|
signing_key:
|
70
71
|
specification_version: 4
|
71
72
|
summary: rspec - Behaves Like a CRUD
|