selleo-controller_tests 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWIwOTJmY2Q4MjAwM2FiYjAwYmJhYjE2NDNiNGNiNWNjZTIzOGM0Zg==
5
+ data.tar.gz: !binary |-
6
+ ZGY4OTFhMDk4NjhmZDczMTk1YzEyZmVhYmRlYWQ0MGY4MDExN2YzOQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MDIyZjc4M2E2N2U3Y2UwMmFhYmM5ZTg2MDczNzc2YmI1NmNkYTk1ZjVkMjhh
10
+ Y2Y0ZjljNTQ2MDBkYWQwZGQxY2ZiMWNiYzVkNDJhMDdiNjU1MTRiYjFkMzNj
11
+ MWY5MDQwOWI3NDZhMDE1NzVhOTg5MDRmYmE3OGZmZmY2ODhkNWQ=
12
+ data.tar.gz: !binary |-
13
+ MTU2NzYyNWFhZGMyZWUyODdhYmJjZmQ5NTZiNTNjMzZjOThmZGMzNTEwNmE5
14
+ YmZhZTIzNTY4OTdjZjdjNWUxMTNkOGJhZTJmYjlmOTJiZjZjYjY2M2U3YzU5
15
+ OTQ0ZmI4OWYxNWU1NWJhNmI1NTdkY2U0NmQzNTVmODg3YmU3NDk=
@@ -0,0 +1,26 @@
1
+ module Selleo
2
+ module ControllerMacros
3
+ def login_user
4
+ let(:current_user) { FactoryGirl.create(:user) }
5
+ before do
6
+ allow(controller).to receive(:current_user).and_return(current_user)
7
+ end
8
+ end
9
+
10
+ def logout_user
11
+ before { allow(controller).to receive(:current_user).and_return(nil) }
12
+ end
13
+
14
+ def with_params(&block)
15
+ _context = context 'with params' do
16
+ before do
17
+ controller.params[:controller] = described_class.name.to_s.underscore.split('_')[0..-2].join('_')
18
+ params.each do |k, v|
19
+ controller.params[k] = v
20
+ end
21
+ end
22
+ end
23
+ _context.class_eval &block
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,22 @@
1
+ shared_examples_for 'an action creating object' do |*args|
2
+ opts = args.extract_options!
3
+
4
+ subject { model_class.last }
5
+
6
+ let(:model_class) { described_class.controller_name.classify.constantize }
7
+ let(:new_attributes) { attributes }
8
+
9
+ if opts[:expect_failure]
10
+ it { expect { call_request }.to_not change { model_class.count }.by(1) }
11
+ else
12
+ it { expect { call_request }.to change { model_class.count }.by(1) }
13
+ end
14
+
15
+ unless opts[:expect_failure]
16
+ context 'after call_request' do
17
+ before { call_request }
18
+
19
+ it { expect(subject.attributes).to include(new_attributes.slice(*args.flatten).stringify_keys)}
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ shared_examples_for 'an action destroying object' do |*args|
2
+ opts = args.extract_options!
3
+
4
+ subject { object }
5
+
6
+ let(:model_name) { described_class.controller_name.singularize }
7
+ let(:object) { public_send(model_name) }
8
+
9
+ if opts[:expect_failure]
10
+ it { expect { call_request }.to_not change { object.class.count }.by(-1) }
11
+ else
12
+ it { expect { call_request }.to change { object.class.count }.by(-1) }
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ shared_examples_for 'an action updating object' do |*args|
2
+ opts = args.extract_options!
3
+
4
+ subject { object }
5
+
6
+ let(:model_name) { described_class.controller_name.singularize }
7
+ let(:object) { public_send(model_name) }
8
+ let(:new_attributes) { attributes }
9
+
10
+ context 'after call_request' do
11
+ before { call_request }
12
+
13
+ if opts[:expect_failure]
14
+ it { expect(subject.reload.attributes).to_not include(new_attributes.slice(*args.flatten).stringify_keys) }
15
+ else
16
+ it { expect(subject.reload.attributes).to include(new_attributes.slice(*args.flatten).stringify_keys) }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ shared_examples 'action handled with service object' do |klass, *args|
2
+ # "CompanyUserCreator" -> "company_user"
3
+
4
+ service_object_name = klass.name.underscore
5
+ resource = service_object_name.split('_')[0..-2].join('_')
6
+
7
+ let(:parameters) { kind_of(resource.classify.constantize) }
8
+
9
+ context klass do
10
+ let(:service_object) { double(service_object_name) }
11
+
12
+ it 'is properly called' do
13
+ expect(klass).to receive(:new).with(*Array.wrap(parameters) ).and_return(service_object)
14
+ expect(service_object).to receive(:save).and_return(true)
15
+ call_request
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,8 @@
1
+ module Selleo
2
+ module XhrPersistence
3
+ def xhr(*)
4
+ allow(@request).to receive(:was_xhr?).and_return(true)
5
+ super
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Selleo
2
+ module ControllerTests
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'selleo-controller_tests/support/controller_macros'
2
+ require 'selleo-controller_tests/support/xhr_persistence'
3
+ require 'selleo-controller_tests/support/shared_examples/controllers/action_creating_object'
4
+ require 'selleo-controller_tests/support/shared_examples/controllers/action_destroying_object'
5
+ require 'selleo-controller_tests/support/shared_examples/controllers/action_updating_object'
6
+ require 'selleo-controller_tests/support/shared_examples/controllers/handled_with_service_object'
7
+
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selleo-controller_tests
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - stevo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Shared examples for controller tests
14
+ email:
15
+ - blazejek@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/selleo-controller_tests/support/controller_macros.rb
21
+ - lib/selleo-controller_tests/support/shared_examples/controllers/action_creating_object.rb
22
+ - lib/selleo-controller_tests/support/shared_examples/controllers/action_destroying_object.rb
23
+ - lib/selleo-controller_tests/support/shared_examples/controllers/action_updating_object.rb
24
+ - lib/selleo-controller_tests/support/shared_examples/controllers/handled_with_service_object.rb
25
+ - lib/selleo-controller_tests/support/xhr_persistence.rb
26
+ - lib/selleo-controller_tests/version.rb
27
+ - lib/selleo_controller_tests.rb
28
+ homepage: https://github.com//selleo-controller_tests
29
+ licenses: []
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project: ! '[none]'
47
+ rubygems_version: 2.1.10
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Shared examples for controller tests
51
+ test_files: []