rspec-behaves-like-crud 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3af43084ca78e0f90510110dd9fa7c92a8745cfa
4
- data.tar.gz: bc62cb8514003eaf7d9486a1f111d5c8a069b2eb
3
+ metadata.gz: 1839f05af8e32266fc7d1f37f28d359acfa4d8b1
4
+ data.tar.gz: 8babf4bd26491a91a22e523f8f2e3c83ab533490
5
5
  SHA512:
6
- metadata.gz: bd3e903cbf904d3515415e3dcb5c8c0112a1326229e16042fc0ea90030d6bcdec179b0aaca6c1e7aaa49e67ccc690e45f624fee0c265257cccea9e37bdeb024e
7
- data.tar.gz: 07d419da48b0dec00adcfd8b2dfb32fddc14fff3e462f6d66629a6f01bca95c587945f109016dbdf2caefb19f1cbc35043b31f6c57484f3537e4266b825efb2d
6
+ metadata.gz: 2b0006326a85894b29ab7e6c596416ab334416e077ce1e14e3c61023bd927c99083b786582288d6ee34cd4b60bc7e20dfc79e9f93189c03095a0c95abf0495ea
7
+ data.tar.gz: 79dfbf34c0da04df556c9bbdd8981757360c6942112f608e27c93fd1ac7b4801bdc5f0e5ee2d0046751692de779b4672d44d7fd8b8086dc682e1384d518a7224
data/README.rdoc CHANGED
@@ -53,4 +53,4 @@ some time by including the general stuff
53
53
 
54
54
  == Collaborators
55
55
 
56
- * anonymous
56
+ * Maciej Tomaka
@@ -1,3 +1,3 @@
1
1
  module RspecBehavesLikeCrud
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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.downcase }
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(:resource_method) { resource_class.to_s.downcase }
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 => valid_attributes }
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 => valid_attributes }
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 => valid_attributes }
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! valid_attributes
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! valid_attributes
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! valid_attributes
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! valid_attributes
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! valid_attributes
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! valid_attributes
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 => valid_attributes }
8
- controller.send(resource_method).attributes.should include(valid_attributes.stringify_keys)
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! valid_attributes
13
- put :update, { id: resource.to_param, param_key => valid_attributes }
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! valid_attributes
19
- put :update, { id: resource.to_param, param_key => valid_attributes }
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! valid_attributes
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! valid_attributes
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
- - skpvox
7
+ - Simon
8
+ - Maciej Tomaka
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-09-06 00:00:00.000000000 Z
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.0.3
69
+ rubygems_version: 2.1.1
69
70
  signing_key:
70
71
  specification_version: 4
71
72
  summary: rspec - Behaves Like a CRUD