rspec_controller_helpers 0.0.2 → 0.0.3

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: 9748d2c99a7307ac8b55f103ffa95c35727c1b80
4
- data.tar.gz: 5308bcaab4412ca9d6bdd99bbad91f56e2ccd7a1
3
+ metadata.gz: b816731a16523117cdac6f32b731ff71bed46b02
4
+ data.tar.gz: 4541661168a86e51362be90c193da3f0eeb765d2
5
5
  SHA512:
6
- metadata.gz: f1a8bf15b98213989415460f879d1eb4825881586c0b76f96ed1ff8a235a5e3fd6901cdfcb9d81dc6b497a768bdffcf1b9158d77e144048fe255595ec5f4b75c
7
- data.tar.gz: 979a5fe82c9a9231fc9d7da70c8c04818844288d9532e5011f37626a49a6ba084d2aed9fc560f8d43abe460e25da07f046b7cfebd19596ae83a2337f10a2aaaf
6
+ metadata.gz: 2e7316be23023c08cd48b15681708dab43c40d6c8bcdca49075d4cfb447cd4936a1818d607e9dde1e64b2688d1893531d71103d8e36d95cc9bc99014573b8eb3
7
+ data.tar.gz: 6b10f3bf98a8dc33731e951e09e1bca23c31f29b0c0e856452964f7a26d46bc7faeeda4f854ee28136ab51913f548b350f03b3b83458315062066d9e8b4dd94b
@@ -0,0 +1,100 @@
1
+ RSpec.shared_examples_for 'a resourceful controller' do |model, raw_options|
2
+ let(:options) { raw_options || {} }
3
+ let(:symbol) { options[:symbol] || model.name.downcase.to_sym }
4
+ let(:factory) { options[:factory] || symbol }
5
+
6
+ let(:tests) do
7
+ all = [:index, :new, :create, :show, :edit, :update, :delete]
8
+ except = options[:except] || []
9
+ options[:only] || (all - except)
10
+ end
11
+
12
+ describe "GET /<resource>" do
13
+ let!(:objects) { create_list(factory, 3) }
14
+ subject { get :index }
15
+
16
+ it "renders the index page" do
17
+ if tests.include? :index
18
+ subject
19
+ expect(response).to have_http_status(:ok)
20
+ expect(response).to render_template(:index)
21
+ end
22
+ end
23
+ end
24
+
25
+ describe "GET /<resource>/new" do
26
+ subject { get :new }
27
+
28
+ it "renders the new page" do
29
+ if tests.include? :new
30
+ subject
31
+ expect(response).to have_http_status(:ok)
32
+ expect(response).to render_template(:new)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe "POST /<resource>" do
38
+ let(:attributes) { attributes_for(factory) }
39
+ subject { post :create, symbol => attributes }
40
+
41
+ it "creates a new object" do
42
+ if tests.include? :create
43
+ expect { subject }.to change { model.count }.by(1)
44
+ end
45
+ end
46
+ end
47
+
48
+ describe "GET /<resource>/:id" do
49
+ let(:object) { create(factory) }
50
+ subject { get :show, id: object.id }
51
+
52
+ it "renders the show page" do
53
+ if tests.include? :show
54
+ subject
55
+ expect(response).to have_http_status(:ok)
56
+ expect(response).to render_template(:show)
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "GET /<resource>/:id/edit" do
62
+ let(:object) { create(factory) }
63
+ subject { get :edit, id: object.id }
64
+
65
+ it "renders the edit page" do
66
+ if tests.include? :edit
67
+ subject
68
+ expect(response).to have_http_status(:ok)
69
+ expect(response).to render_template(:edit)
70
+ end
71
+ end
72
+ end
73
+
74
+ describe "PATCH /<resource>/:id" do
75
+ let(:object) { create(factory) }
76
+ let(:new_attributes) { attributes_for(factory) }
77
+ subject { patch :update, id: object.id, symbol => new_attributes }
78
+
79
+ it "updates the object" do
80
+ if tests.include? :update
81
+ subject
82
+ object.reload
83
+ new_attributes.each do |k, v|
84
+ expect(object.send(k)).to eq(v)
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ describe "DELETE /<resource>/:id" do
91
+ let!(:object) { create(factory) }
92
+ subject { delete :destroy, id: object.id }
93
+
94
+ it "deletes the object" do
95
+ if tests.include? :destroy
96
+ expect { subject }.to change { model.count }.by(-1)
97
+ end
98
+ end
99
+ end
100
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_controller_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Kniffin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-18 00:00:00.000000000 Z
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-rails
@@ -45,6 +45,7 @@ extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
47
  - lib/rspec_controller_helpers.rb
48
+ - lib/rspec_controller_helpers/resourceful.rb
48
49
  homepage: https://github.com/dkniffin/rspec_controller_helpers
49
50
  licenses:
50
51
  - MIT