rspec-behaves-like-crud 0.0.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +56 -0
- data/Rakefile +21 -0
- data/lib/rspec_behaves_like_crud/version.rb +3 -0
- data/lib/rspec_behaves_like_crud.rb +7 -0
- data/lib/spec/support/mixins/incrudable.rb +11 -0
- data/lib/spec/support/shared_examples/crud_controller_spec.rb +9 -0
- data/lib/spec/support/shared_examples/crud_create_spec.rb +36 -0
- data/lib/spec/support/shared_examples/crud_delete_spec.rb +18 -0
- data/lib/spec/support/shared_examples/crud_edit_spec.rb +9 -0
- data/lib/spec/support/shared_examples/crud_index_spec.rb +9 -0
- data/lib/spec/support/shared_examples/crud_new_spec.rb +8 -0
- data/lib/spec/support/shared_examples/crud_show_spec.rb +9 -0
- data/lib/spec/support/shared_examples/crud_update_spec.rb +40 -0
- data/lib/tasks/rspec_behaves_like_crud_tasks.rake +4 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3af43084ca78e0f90510110dd9fa7c92a8745cfa
|
4
|
+
data.tar.gz: bc62cb8514003eaf7d9486a1f111d5c8a069b2eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bd3e903cbf904d3515415e3dcb5c8c0112a1326229e16042fc0ea90030d6bcdec179b0aaca6c1e7aaa49e67ccc690e45f624fee0c265257cccea9e37bdeb024e
|
7
|
+
data.tar.gz: 07d419da48b0dec00adcfd8b2dfb32fddc14fff3e462f6d66629a6f01bca95c587945f109016dbdf2caefb19f1cbc35043b31f6c57484f3537e4266b825efb2d
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 skpvox
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
= rspec - Behaves Like CRUD
|
2
|
+
|
3
|
+
You've DRYed up your controllers by using decent_exposure.
|
4
|
+
|
5
|
+
Now it's time to DRY up your controller specs as well.
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
|
9
|
+
Add this to your Gemfile:
|
10
|
+
|
11
|
+
gem 'rspec-behaves-like-crud'
|
12
|
+
|
13
|
+
Add this to your spec_helper:
|
14
|
+
|
15
|
+
require 'rspec_behaves_like_crud'
|
16
|
+
|
17
|
+
== Usage
|
18
|
+
|
19
|
+
Then just add the following lines to your controller spec.
|
20
|
+
|
21
|
+
let(:valid_attributes) { FactoryGirl.attributes_for(:campaign) }
|
22
|
+
let(:invalid_attributes) { { 'url' => nil } }
|
23
|
+
let(:resource_class) { Campaign }
|
24
|
+
|
25
|
+
include Incrudable
|
26
|
+
|
27
|
+
it_behaves_like 'a CRUD controller'
|
28
|
+
|
29
|
+
|
30
|
+
If you want to custom test some actions, you can still save yourself
|
31
|
+
some time by including the general stuff
|
32
|
+
|
33
|
+
let(:valid_attributes) { FactoryGirl.attributes_for(:campaign) }
|
34
|
+
let(:invalid_attributes) { { 'url' => nil } }
|
35
|
+
let(:resource_class) { Campaign }
|
36
|
+
|
37
|
+
include Incrudable
|
38
|
+
|
39
|
+
describe "GET show" do
|
40
|
+
it "responds in a custom way" do
|
41
|
+
# Custom tests ...
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it_behaves_like 'a CRUD index'
|
46
|
+
it_behaves_like 'a CRUD new'
|
47
|
+
it_behaves_like 'a CRUD edit'
|
48
|
+
it_behaves_like 'a CRUD delete'
|
49
|
+
it_behaves_like 'a CRUD create'
|
50
|
+
it_behaves_like 'a CRUD update'
|
51
|
+
|
52
|
+
# ^^ Note that it_behaves_like 'a CRUD show' is missing
|
53
|
+
|
54
|
+
== Collaborators
|
55
|
+
|
56
|
+
* anonymous
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'RspecBehavesLikeCrud'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
Bundler::GemHelper.install_tasks
|
21
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Incrudable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
let(:resource_name) { resource_class.to_s.titlecase }
|
6
|
+
let(:param_key) { resource_class.to_s.downcase }
|
7
|
+
|
8
|
+
let(:resource_method) { resource_class.to_s.downcase }
|
9
|
+
let(:collection_method) { resource_class.to_s.downcase.pluralize }
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
shared_examples 'a CRUD controller' do
|
2
|
+
it_behaves_like 'a CRUD index'
|
3
|
+
it_behaves_like 'a CRUD new'
|
4
|
+
it_behaves_like 'a CRUD show'
|
5
|
+
it_behaves_like 'a CRUD edit'
|
6
|
+
it_behaves_like 'a CRUD delete'
|
7
|
+
it_behaves_like 'a CRUD create'
|
8
|
+
it_behaves_like 'a CRUD update'
|
9
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
shared_examples 'a CRUD create' do
|
2
|
+
describe 'POST create' do
|
3
|
+
describe 'with valid params' do
|
4
|
+
it 'creates a new resource' do
|
5
|
+
expect do
|
6
|
+
post :create, { param_key => valid_attributes }
|
7
|
+
end.to change(resource_class, :count).by(1)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'exposes a newly created resource' do
|
11
|
+
post :create, { param_key => valid_attributes }
|
12
|
+
controller.send(resource_method).should be_a(resource_class)
|
13
|
+
controller.send(resource_method).should be_persisted
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'redirects to the created resource' do
|
17
|
+
post :create, { param_key => valid_attributes }
|
18
|
+
response.should redirect_to(resource_class.last)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'with invalid params' do
|
23
|
+
it 'exposes a newly created but unsaved resource' do
|
24
|
+
resource_class.any_instance.stub(:save).and_return(false)
|
25
|
+
post :create, { param_key => invalid_attributes }
|
26
|
+
controller.send(resource_method).should be_a_new(resource_class)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "re-renders the 'new' template" do
|
30
|
+
resource_class.any_instance.stub(:save).and_return(false)
|
31
|
+
post :create, { param_key => invalid_attributes }
|
32
|
+
response.should render_template('new')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
shared_examples 'a CRUD delete' do
|
2
|
+
|
3
|
+
describe 'DELETE destroy' do
|
4
|
+
it 'destroys the requested resource' do
|
5
|
+
resource = resource_class.create! valid_attributes
|
6
|
+
expect do
|
7
|
+
delete :destroy, { id: resource.to_param }
|
8
|
+
end.to change(resource_class, :count).by(-1)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'redirects to the list' do
|
12
|
+
resource = resource_class.create! valid_attributes
|
13
|
+
delete :destroy, { id: resource.to_param }
|
14
|
+
response.should redirect_to(send("#{resource_class.to_s.tableize}_url"))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
shared_examples 'a CRUD update' do
|
2
|
+
describe 'PUT update' do
|
3
|
+
describe 'with valid params' do
|
4
|
+
it 'updates the requested resource' do
|
5
|
+
resource = resource_class.create! valid_attributes
|
6
|
+
resource_class.any_instance.should_receive(:save)
|
7
|
+
put :update, { id: resource.to_param, param_key => valid_attributes }
|
8
|
+
controller.send(resource_method).attributes.should include(valid_attributes.stringify_keys)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'exposes the requested resource' do
|
12
|
+
resource = resource_class.create! valid_attributes
|
13
|
+
put :update, { id: resource.to_param, param_key => valid_attributes }
|
14
|
+
controller.send(resource_method).should eq(resource)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'redirects to the resource' do
|
18
|
+
resource = resource_class.create! valid_attributes
|
19
|
+
put :update, { id: resource.to_param, param_key => valid_attributes }
|
20
|
+
response.should redirect_to(resource)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'with invalid params' do
|
25
|
+
it 'assigns the resource' do
|
26
|
+
resource = resource_class.create! valid_attributes
|
27
|
+
resource_class.any_instance.stub(:save).and_return(false)
|
28
|
+
put :update, { id: resource.to_param, param_key => invalid_attributes }
|
29
|
+
controller.send(resource_method).should eq(resource)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "re-renders the 'edit' template" do
|
33
|
+
resource = resource_class.create! valid_attributes
|
34
|
+
resource_class.any_instance.stub(:save).and_return(false)
|
35
|
+
put :update, { id: resource.to_param, param_key => invalid_attributes }
|
36
|
+
response.should render_template('edit')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-behaves-like-crud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- skpvox
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
description: You've DRYed up your controllers. Now DRY up your controller specs.
|
28
|
+
email:
|
29
|
+
- skpvox@github.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- lib/rspec_behaves_like_crud/version.rb
|
35
|
+
- lib/rspec_behaves_like_crud.rb
|
36
|
+
- lib/spec/support/mixins/incrudable.rb
|
37
|
+
- lib/spec/support/shared_examples/crud_controller_spec.rb
|
38
|
+
- lib/spec/support/shared_examples/crud_create_spec.rb
|
39
|
+
- lib/spec/support/shared_examples/crud_delete_spec.rb
|
40
|
+
- lib/spec/support/shared_examples/crud_edit_spec.rb
|
41
|
+
- lib/spec/support/shared_examples/crud_index_spec.rb
|
42
|
+
- lib/spec/support/shared_examples/crud_new_spec.rb
|
43
|
+
- lib/spec/support/shared_examples/crud_show_spec.rb
|
44
|
+
- lib/spec/support/shared_examples/crud_update_spec.rb
|
45
|
+
- lib/tasks/rspec_behaves_like_crud_tasks.rake
|
46
|
+
- MIT-LICENSE
|
47
|
+
- Rakefile
|
48
|
+
- README.rdoc
|
49
|
+
homepage: https://github.com/skpvox/rspec-behaves-like-crud
|
50
|
+
licenses: []
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 2.0.3
|
69
|
+
signing_key:
|
70
|
+
specification_version: 4
|
71
|
+
summary: rspec - Behaves Like a CRUD
|
72
|
+
test_files: []
|