zertico 1.3.0 → 2.0.0.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.hound.yml +17 -0
- data/.travis.yml +36 -23
- data/CHANGELOG.md +103 -0
- data/README.md +39 -19
- data/gemfiles/Gemfile.rails3-ruby1.8.7 +7 -0
- data/gemfiles/Gemfile.rails3-ruby1.9.2+ +6 -0
- data/gemfiles/Gemfile.rails4-ruby1.9.2+ +5 -0
- data/lib/zertico.rb +1 -0
- data/lib/zertico/controller.rb +24 -16
- data/lib/zertico/delegator.rb +12 -5
- data/lib/zertico/exceptions.rb +1 -0
- data/lib/zertico/exceptions/missing_strong_parameters.rb +9 -0
- data/lib/zertico/interactor.rb +15 -2
- data/lib/zertico/organizer.rb +7 -5
- data/lib/zertico/permitted_params.rb +21 -0
- data/lib/zertico/responder.rb +16 -31
- data/lib/zertico/responder/force_redirect.rb +34 -0
- data/lib/zertico/responder/pjax.rb +13 -0
- data/lib/zertico/service.rb +5 -62
- data/lib/zertico/service/class_methods.rb +29 -0
- data/lib/zertico/service/instance_methods.rb +60 -0
- data/lib/zertico/version.rb +1 -1
- data/spec/fake_app/app/controllers/admin/user_controller.rb +6 -0
- data/spec/fake_app/app/controllers/application_controller.rb +7 -0
- data/spec/fake_app/app/controllers/person/gifts_controller.rb +6 -0
- data/spec/fake_app/app/controllers/person/profile_controller.rb +6 -0
- data/spec/fake_app/app/controllers/user_controller.rb +2 -0
- data/spec/fake_app/app/controllers/users_controller.rb +7 -0
- data/spec/fake_app/{delegators → app/delegators}/admin/user_delegator.rb +0 -0
- data/spec/fake_app/{delegators → app/delegators}/profile/profile_delegator.rb +0 -0
- data/spec/fake_app/{delegators → app/delegators}/user_delegator.rb +0 -0
- data/spec/fake_app/{interactors → app/interactors}/create_invoice_interactor.rb +0 -0
- data/spec/fake_app/{interactors → app/interactors}/create_product_interactor.rb +0 -0
- data/spec/fake_app/{interactors → app/interactors}/create_user_interactor.rb +0 -0
- data/spec/fake_app/{interactors → app/interactors}/send_welcome_email_interactor.rb +0 -0
- data/spec/fake_app/{interfaces → app/interfaces}/invoice.rb +0 -0
- data/spec/fake_app/{interfaces → app/interfaces}/person/profile.rb +0 -0
- data/spec/fake_app/{interfaces → app/interfaces}/product.rb +0 -0
- data/spec/fake_app/app/interfaces/user.rb +32 -0
- data/spec/fake_app/{organizers → app/organizers}/buy_product_organizer.rb +0 -0
- data/spec/fake_app/{organizers → app/organizers}/register_organizer.rb +0 -0
- data/spec/fake_app/app/permitted_params/users_permitted_params.rb +9 -0
- data/spec/fake_app/app/responders/users_responder.rb +5 -0
- data/spec/fake_app/app/services/admin/user_service.rb +6 -0
- data/spec/fake_app/app/services/person/gifts_service.rb +4 -0
- data/spec/fake_app/app/services/person/profile_service.rb +4 -0
- data/spec/fake_app/app/services/user_service.rb +5 -0
- data/spec/fake_app/app/services/users_service.rb +3 -0
- data/spec/fake_app/app/views/layouts/application.html.erb +1 -0
- data/spec/fake_app/app/views/users/edit.html.erb +0 -0
- data/spec/fake_app/app/views/users/index.html.erb +0 -0
- data/spec/fake_app/app/views/users/new.html.erb +0 -0
- data/spec/fake_app/app/views/users/show.html.erb +0 -0
- data/spec/fake_app/config/application.rb +10 -0
- data/spec/fake_app/config/routes.rb +3 -0
- data/spec/fake_app/config/secrets.yml +4 -0
- data/spec/spec_helper.rb +17 -3
- data/spec/zertico/controller_integration_spec.rb +92 -0
- data/spec/zertico/controller_spec.rb +14 -151
- data/spec/zertico/delegator_spec.rb +60 -11
- data/spec/zertico/interactor_spec.rb +41 -1
- data/spec/zertico/organizer_spec.rb +21 -4
- data/spec/zertico/permitted_params_spec.rb +25 -0
- data/spec/zertico/responder_spec.rb +234 -0
- data/spec/zertico/service/class_methods_spec.rb +36 -0
- data/spec/zertico/service/instance_methods_spec.rb +218 -0
- data/zertico.gemspec +10 -2
- metadata +139 -55
- data/gemfiles/Gemfile.rails3.1 +0 -5
- data/gemfiles/Gemfile.rails3.2 +0 -5
- data/gemfiles/Gemfile.rails4.0 +0 -5
- data/gemfiles/Gemfile.rails4.1 +0 -5
- data/spec/fake_app/controllers/admin/user_controller.rb +0 -4
- data/spec/fake_app/controllers/profile/profile_controller.rb +0 -4
- data/spec/fake_app/controllers/user_controller.rb +0 -2
- data/spec/fake_app/controllers/users_controller.rb +0 -2
- data/spec/fake_app/interfaces/user.rb +0 -9
- data/spec/fake_app/services/admin/user_service.rb +0 -8
- data/spec/fake_app/services/person/profile_service.rb +0 -5
- data/spec/fake_app/services/user_service.rb +0 -6
- data/spec/zertico/service_spec.rb +0 -162
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
attr_reader :updated, :destroyed
|
3
|
+
attr_accessor :name, :id
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@updated = false
|
7
|
+
@destroyed = false
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.all
|
12
|
+
[new, new]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.find(id)
|
16
|
+
new
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.create(params)
|
20
|
+
new
|
21
|
+
end
|
22
|
+
|
23
|
+
def update_attributes(params)
|
24
|
+
@updated = true
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def destroy
|
29
|
+
@destroyed = true
|
30
|
+
true
|
31
|
+
end
|
32
|
+
end
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'action_controller/railtie'
|
3
|
+
|
4
|
+
module RailsApplication
|
5
|
+
class Application < Rails::Application
|
6
|
+
config.root = "#{config.root}/spec/fake_app"
|
7
|
+
config.logger = nil
|
8
|
+
config.secret_key_base = YAML.load(File.open("#{Rails.root}/config/secrets.yml"))[Rails.env]['secret_key_base']
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,4 @@
|
|
1
|
+
development:
|
2
|
+
secret_key_base: cf8a9ddeff8bc751c177a6c9fd892f23442e94ada03ca27ceeaefd5639bfe882fbba6b79ee4181d8dba71949f3642f56c3427102c4f1659fc023bddf56fee5dc
|
3
|
+
test:
|
4
|
+
secret_key_base: 477d9a34cbff7bb338134fa8b9a5aa9e672949a1532f6949f5f69bc950c94ff9b463d035c1c20f008c66508fda1f62454814e8ad6e5b2105bf6fb24a56395845
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
require 'rspec'
|
2
|
-
require '
|
2
|
+
require 'active_record'
|
3
3
|
|
4
|
-
|
4
|
+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
|
5
|
+
ActiveRecord::Migration.create_table :users
|
6
|
+
|
7
|
+
if ENV['COVERAGE']
|
8
|
+
require 'simplecov'
|
9
|
+
require 'coveralls'
|
10
|
+
|
11
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
12
|
+
SimpleCov.start do
|
13
|
+
add_filter "#{File.dirname(__FILE__)}/fake_app"
|
14
|
+
end
|
15
|
+
|
16
|
+
Coveralls.wear!
|
17
|
+
end
|
5
18
|
|
6
19
|
require "#{File.dirname(__FILE__)}/../lib/zertico"
|
7
20
|
|
8
|
-
Dir["#{File.dirname(__FILE__)}/fake_app/**/*.rb"].sort.each { |f| require f }
|
21
|
+
Dir["#{File.dirname(__FILE__)}/fake_app/config/**/*.rb"].sort.each { |f| require f }
|
22
|
+
Dir["#{File.dirname(__FILE__)}/fake_app/app/**/*.rb"].sort.each { |f| require f }
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec/rails'
|
3
|
+
|
4
|
+
describe UsersController, :type => :controller do
|
5
|
+
let(:user) { User.new }
|
6
|
+
|
7
|
+
context '#index' do
|
8
|
+
before :each do
|
9
|
+
get :index
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should initialize a collection of users' do
|
13
|
+
expect(assigns(:users)).to be_an_instance_of(Array)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should initialize a collection with two itens' do
|
17
|
+
expect(assigns(:users).size).to be_equal 2
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context '#new' do
|
22
|
+
before :each do
|
23
|
+
get :new
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should initialize an user' do
|
27
|
+
expect(assigns(:user)).to be_an_instance_of(User)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '#show' do
|
32
|
+
before :each do
|
33
|
+
get :show, :id => 1
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should find and initialize an user' do
|
37
|
+
expect(assigns(:user)).to be_an_instance_of(User)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context '#edit' do
|
42
|
+
before :each do
|
43
|
+
get :edit, :id => 1
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should find and initialize an user' do
|
47
|
+
expect(assigns(:user)).to be_an_instance_of(User)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context '#create' do
|
52
|
+
before :each do
|
53
|
+
post :create, :user => { :name => 'name' }
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should pass the right parameters to the model' do
|
57
|
+
expect(User).to receive(:create).with(:name => 'name').and_return(user)
|
58
|
+
post :create, :user => { :name => 'name' }
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should create a new user' do
|
62
|
+
expect(assigns(:user)).to be_an_instance_of(User)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context '#update' do
|
67
|
+
before :each do
|
68
|
+
allow(User).to receive(:find).and_return(user)
|
69
|
+
allow(user).to receive(:id).and_return(3)
|
70
|
+
put :update, :id => 1, :user => { :id => 23 }
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should pass the right parameters to the model' do
|
74
|
+
expect(user).to receive(:update_attributes).with('id' => '23').and_return(true)
|
75
|
+
put :update, :id => 1, :user => { :id => 23 }
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should update an user' do
|
79
|
+
expect(assigns(:user)).to be_an_instance_of(User)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
context '#destroy' do
|
84
|
+
before :each do
|
85
|
+
delete :destroy, :id => 1
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should destroy the user' do
|
89
|
+
expect(assigns(:user)).to be_an_instance_of(User)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -1,168 +1,31 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Zertico::Controller do
|
4
|
-
let(:controller) {
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
|
8
|
-
context 'not being nested' do
|
9
|
-
it 'should find on the correct id' do
|
10
|
-
user_controller.send(:interface_id).should == 'id'
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'being nested' do
|
15
|
-
it 'should find on the correct id' do
|
16
|
-
admin_controller.send(:interface_id).should == 'user_id'
|
17
|
-
end
|
18
|
-
end
|
4
|
+
let(:controller) { UsersController.new }
|
5
|
+
let(:zertico_controller) { Zertico::Controller.new }
|
6
|
+
let(:service) { Zertico::Service.new }
|
19
7
|
|
20
8
|
context 'without a custom service' do
|
21
|
-
it 'should
|
22
|
-
|
9
|
+
it 'should initialize Zertico::Service' do
|
10
|
+
expect(zertico_controller.service).to be_an_instance_of(Zertico::Service)
|
23
11
|
end
|
24
12
|
end
|
25
13
|
|
26
14
|
context 'with a custom service' do
|
27
|
-
it 'should
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should extend it!' do
|
32
|
-
user_controller.should respond_to :user
|
15
|
+
it 'should initialize it!' do
|
16
|
+
expect(controller.service).to be_an_instance_of(UsersService)
|
33
17
|
end
|
34
18
|
end
|
35
19
|
|
36
|
-
context '
|
37
|
-
|
38
|
-
|
39
|
-
controller.stub(:respond_with).with('responder', 'options')
|
40
|
-
end
|
41
|
-
|
42
|
-
context '#index' do
|
43
|
-
before :each do
|
44
|
-
controller.stub(:all => 'responder')
|
45
|
-
end
|
46
|
-
|
47
|
-
after :each do
|
48
|
-
controller.index
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should initialize a collection of objects' do
|
52
|
-
controller.should_receive(:all)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should respond correctly' do
|
56
|
-
controller.should_receive(:respond_with).with('responder', 'options')
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context '#new' do
|
61
|
-
before :each do
|
62
|
-
controller.stub(:build => 'responder')
|
63
|
-
end
|
64
|
-
|
65
|
-
after :each do
|
66
|
-
controller.new
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'should initialize an object' do
|
70
|
-
controller.should_receive(:build)
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should respond correctly' do
|
74
|
-
controller.should_receive(:respond_with).with('responder', 'options')
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
context '#show' do
|
79
|
-
before :each do
|
80
|
-
controller.stub(:find => 'responder')
|
81
|
-
end
|
82
|
-
|
83
|
-
after :each do
|
84
|
-
controller.show
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'should initialize an object' do
|
88
|
-
controller.should_receive(:find)
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'should respond correctly' do
|
92
|
-
controller.should_receive(:respond_with).with('responder', 'options')
|
93
|
-
end
|
20
|
+
context 'without a custom responder' do
|
21
|
+
it 'should initialize Zertico::Responder' do
|
22
|
+
expect(zertico_controller.responder).to be == Zertico::Responder
|
94
23
|
end
|
24
|
+
end
|
95
25
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
after :each do
|
102
|
-
controller.edit
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should initialize an object' do
|
106
|
-
controller.should_receive(:find)
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should respond correctly' do
|
110
|
-
controller.should_receive(:respond_with).with('responder', 'options')
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context '#create' do
|
115
|
-
before :each do
|
116
|
-
controller.stub(:generate => 'responder')
|
117
|
-
end
|
118
|
-
|
119
|
-
after :each do
|
120
|
-
controller.create
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'should initialize an object' do
|
124
|
-
controller.should_receive(:generate)
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'should respond correctly' do
|
128
|
-
controller.should_receive(:respond_with).with('responder', 'options')
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
context '#update' do
|
133
|
-
before :each do
|
134
|
-
controller.stub(:modify => 'responder')
|
135
|
-
end
|
136
|
-
|
137
|
-
after :each do
|
138
|
-
controller.update
|
139
|
-
end
|
140
|
-
|
141
|
-
it 'should initialize an object' do
|
142
|
-
controller.should_receive(:modify)
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'should respond correctly' do
|
146
|
-
controller.should_receive(:respond_with).with('responder', 'options')
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
context '#destroy' do
|
151
|
-
before :each do
|
152
|
-
controller.stub(:delete => 'responder')
|
153
|
-
end
|
154
|
-
|
155
|
-
after :each do
|
156
|
-
controller.destroy
|
157
|
-
end
|
158
|
-
|
159
|
-
it 'should initialize an object' do
|
160
|
-
controller.should_receive(:delete)
|
161
|
-
end
|
162
|
-
|
163
|
-
it 'should respond correctly' do
|
164
|
-
controller.should_receive(:respond_with).with('responder', 'options')
|
165
|
-
end
|
26
|
+
context 'with a custom responder' do
|
27
|
+
it 'should initialize it!' do
|
28
|
+
expect(controller.responder).to be == UsersResponder
|
166
29
|
end
|
167
30
|
end
|
168
31
|
end
|
@@ -2,55 +2,104 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Zertico::Delegator do
|
4
4
|
let(:user) { User.new }
|
5
|
-
let(:
|
5
|
+
let(:product) { Product.new }
|
6
|
+
let(:user_delegator) { UserDelegator.new }
|
6
7
|
|
7
8
|
context 'on a namespaced delegator and interface model' do
|
8
9
|
it 'should find the interface model' do
|
9
|
-
Person::ProfileDelegator.send(:interface_class).
|
10
|
+
expect(Person::ProfileDelegator.send(:interface_class)).to eq(Person::Profile)
|
10
11
|
end
|
11
12
|
|
12
13
|
it 'should return a valid instance variable name' do
|
13
|
-
Person::ProfileDelegator.send(:interface_name).
|
14
|
+
expect(Person::ProfileDelegator.send(:interface_name)).to eq('profile')
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
17
18
|
context 'on a namespaced delegator and non namespaced interface model' do
|
18
19
|
it 'should find the interface model' do
|
19
|
-
Admin::UserDelegator.send(:interface_class).
|
20
|
+
expect(Admin::UserDelegator.send(:interface_class)).to eq(User)
|
20
21
|
end
|
21
22
|
|
22
23
|
it 'should return a valid instance variable name' do
|
23
|
-
Admin::UserDelegator.send(:interface_name).
|
24
|
+
expect(Admin::UserDelegator.send(:interface_name)).to eq('user')
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
27
28
|
context 'on a non namespaced delegator and non namespaced interface model' do
|
28
29
|
it 'should find the interface model' do
|
29
|
-
UserDelegator.send(:interface_class).
|
30
|
+
expect(UserDelegator.send(:interface_class)).to eq(User)
|
30
31
|
end
|
31
32
|
|
32
33
|
it 'should return a valid instance variable name' do
|
33
|
-
UserDelegator.send(:interface_name).
|
34
|
+
expect(UserDelegator.send(:interface_name)).to eq('user')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.new' do
|
39
|
+
context 'without params' do
|
40
|
+
it "should initialize an object based on delegator's name" do
|
41
|
+
expect(UserDelegator.new.interface).to be_an_instance_of(User)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'with an object as param' do
|
46
|
+
it 'use this object' do
|
47
|
+
expect(UserDelegator.new(product).interface).to be_an_instance_of(Product)
|
48
|
+
end
|
34
49
|
end
|
35
50
|
end
|
36
51
|
|
37
52
|
describe '.find' do
|
38
53
|
before :each do
|
39
|
-
User.
|
54
|
+
allow(User).to receive(:find).and_return(user)
|
40
55
|
end
|
41
56
|
|
42
57
|
it 'should return an delegator' do
|
43
|
-
UserDelegator.find(3).
|
58
|
+
expect(UserDelegator.find(3)).to be_an_instance_of(UserDelegator)
|
44
59
|
end
|
45
60
|
end
|
46
61
|
|
47
62
|
describe '#interface' do
|
48
63
|
before :each do
|
49
|
-
User.
|
64
|
+
allow(User).to receive(:find).and_return(user)
|
50
65
|
end
|
51
66
|
|
52
67
|
it 'should return the interface object' do
|
53
|
-
UserDelegator.find(3).interface.
|
68
|
+
expect(UserDelegator.find(3).interface).to eq(user)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#interface=' do
|
73
|
+
before :each do
|
74
|
+
user_delegator.interface = product
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should set the interface object' do
|
78
|
+
expect(user_delegator.interface).to eq(product)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '.interface_name' do
|
83
|
+
it 'should return the interface name' do
|
84
|
+
expect(UserDelegator.interface_name).to eq('user')
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '.interface_class' do
|
89
|
+
it 'should return the interface name' do
|
90
|
+
expect(UserDelegator.interface_class).to eq(User)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#interface_name' do
|
95
|
+
it 'should return the interface name' do
|
96
|
+
expect(user_delegator.send(:interface_name)).to eq('user')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#interface_class' do
|
101
|
+
it 'should return the interface name' do
|
102
|
+
expect(user_delegator.send(:interface_class)).to eq(User)
|
54
103
|
end
|
55
104
|
end
|
56
105
|
end
|