zertico 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +106 -42
- data/lib/zertico.rb +6 -2
- data/lib/zertico/accessor.rb +2 -50
- data/lib/zertico/delegator.rb +35 -0
- data/lib/zertico/exceptions.rb +5 -0
- data/lib/zertico/exceptions/rollback_exception.rb +6 -0
- data/lib/zertico/interactor.rb +23 -0
- data/lib/zertico/organizer.rb +26 -0
- data/lib/zertico/version.rb +1 -1
- data/spec/fake_app/{admin → controllers/admin}/user_controller.rb +0 -0
- data/spec/fake_app/{person → controllers/profile}/profile_controller.rb +0 -0
- data/spec/fake_app/{user_controller.rb → controllers/user_controller.rb} +0 -0
- data/spec/fake_app/{users_controller.rb → controllers/users_controller.rb} +1 -1
- data/spec/fake_app/delegators/admin/user_delegator.rb +4 -0
- data/spec/fake_app/delegators/profile/profile_delegator.rb +4 -0
- data/spec/fake_app/delegators/user_delegator.rb +2 -0
- data/spec/fake_app/interactors/create_invoice_interactor.rb +9 -0
- data/spec/fake_app/interactors/create_product_interactor.rb +9 -0
- data/spec/fake_app/interactors/create_user_interactor.rb +9 -0
- data/spec/fake_app/interactors/send_welcome_email_interactor.rb +5 -0
- data/spec/fake_app/interfaces/invoice.rb +9 -0
- data/spec/fake_app/{person → interfaces/person}/profile.rb +0 -0
- data/spec/fake_app/interfaces/product.rb +9 -0
- data/spec/fake_app/interfaces/user.rb +9 -0
- data/spec/fake_app/organizers/buy_product_organizer.rb +5 -0
- data/spec/fake_app/organizers/register_organizer.rb +5 -0
- data/spec/fake_app/{admin → services/admin}/user_service.rb +0 -0
- data/spec/fake_app/{person → services/person}/profile_service.rb +0 -0
- data/spec/fake_app/{user_service.rb → services/user_service.rb} +0 -0
- data/spec/zertico/delegator_spec.rb +56 -0
- data/spec/zertico/interactor_spec.rb +11 -0
- data/spec/zertico/organizer_spec.rb +34 -0
- data/zertico.gemspec +3 -2
- metadata +55 -30
- data/spec/fake_app/admin/user_accessor.rb +0 -4
- data/spec/fake_app/person/profile_accessor.rb +0 -4
- data/spec/fake_app/user.rb +0 -5
- data/spec/fake_app/user_accessor.rb +0 -2
- data/spec/zertico/accessor_spec.rb +0 -63
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1295fd48c55975eb821b72ef4aecbf18718a1ba8
|
4
|
+
data.tar.gz: 42084f48151b1c217ba9f06457f88b891957559c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee89cd13512c57ee180a2c77740066dfdcb310642b7d77af31e54a8d5e353fe6b5fee1cf6f033815f7f500bcb8f8d018c249387b8b4112efdde121639da185e3
|
7
|
+
data.tar.gz: 9a9dc13bb60edc54a4d84e982e7e7c15c1b8ba626cf9c6c1880f2500529b7e77fa3c75641e0a6f97ca5112354953b235e2ed07ae05f05fdae2566906f7be2fea
|
data/README.md
CHANGED
@@ -2,10 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/zertico.png)](http://badge.fury.io/rb/zertico) [![Build Status](https://travis-ci.org/zertico/zertico.png)](https://travis-ci.org/zertico/zertico) [![Dependency Status](https://gemnasium.com/zertico/zertico.png)](https://gemnasium.com/zertico/zertico) [![Coverage Status](https://coveralls.io/repos/zertico/zertico/badge.png?branch=master)](https://coveralls.io/r/zertico/zertico) [![Code Climate](https://codeclimate.com/github/zertico/zertico.png)](https://codeclimate.com/github/zertico/zertico)
|
4
4
|
|
5
|
-
|
6
|
-
Rails is a great framework, but is not a great idea to let your tests depend on any part of it.
|
7
|
-
Zertico let you develop what most important: your business logic. Also, your tests will not depend
|
8
|
-
of rails at all.
|
5
|
+
Increase your Rails development speed using patterns that will make your code even more easy to read and maintain.
|
9
6
|
|
10
7
|
## Installation
|
11
8
|
|
@@ -20,73 +17,140 @@ And then execute:
|
|
20
17
|
Or install it yourself as:
|
21
18
|
|
22
19
|
$ gem install zertico
|
23
|
-
|
24
|
-
##
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
|
21
|
+
## Tools
|
22
|
+
|
23
|
+
### Zertico::Accessor
|
24
|
+
|
25
|
+
It is deprecated. Please use `Zertico::Delegator` instead.
|
26
|
+
|
27
|
+
### Zertico::Controller
|
28
|
+
|
29
|
+
The `Zertico::Controller` define behavior of a common Rails Controller. By Extending it, your controllers will be more smart,
|
30
|
+
they will know which model instantiate and where to redirect when needed.
|
31
|
+
|
32
|
+
All you need to do is extend ith with you `ApplicationController` and you will get the benefit of it.
|
33
|
+
|
28
34
|
```ruby
|
29
|
-
class ApplicationController <
|
35
|
+
class ApplicationController < ZerticoController
|
36
|
+
respond_to :html
|
30
37
|
end
|
31
|
-
```
|
38
|
+
```
|
32
39
|
|
33
|
-
|
40
|
+
### Zertico::Delegator
|
34
41
|
|
42
|
+
The `Zertico::Delegator` is a delegator with some extra tools to work with `ActiveRecord`. It will try to guess your model,
|
43
|
+
and initialize it.
|
44
|
+
|
35
45
|
```ruby
|
36
|
-
|
46
|
+
class UserDelegator < Zertico::Delegator
|
47
|
+
def name
|
48
|
+
interface.name.downcase
|
49
|
+
end
|
50
|
+
end
|
37
51
|
```
|
38
52
|
|
39
|
-
|
40
|
-
|
41
|
-
## Advanced Usage
|
53
|
+
In the above example, it will automatically load a `User` model.
|
42
54
|
|
43
|
-
|
44
|
-
create a service with the same name of the controller, as follows:
|
55
|
+
### Zertico::Interactor
|
45
56
|
|
57
|
+
The `Zertico::Interactor` defines a single call on a transaction at the ruby interpreter level. It can be used to define a
|
58
|
+
database call, api call, sending of an email, calculate some data based on another interactor.
|
59
|
+
|
46
60
|
```ruby
|
47
|
-
class
|
61
|
+
class CreateUserInteractor < Zertico::Interactor
|
62
|
+
def perform(params)
|
63
|
+
@user = User.create(params)
|
64
|
+
end
|
65
|
+
|
66
|
+
def rollback
|
67
|
+
@user.destroy
|
68
|
+
end
|
69
|
+
end
|
48
70
|
```
|
71
|
+
|
72
|
+
It should define its `perform` logic and `rollback` logic in case some other interactor fails.
|
73
|
+
|
74
|
+
### Zertico::Organizer
|
49
75
|
|
76
|
+
The `Zertico::Organizer` is the responsible for calling a pack of interactors, and in case of some failure, send a
|
77
|
+
rollback signal for all other interactors already executed.
|
78
|
+
|
50
79
|
```ruby
|
51
|
-
module
|
52
|
-
|
80
|
+
module CreateProduct
|
81
|
+
extend Zertico::Organizer
|
82
|
+
|
83
|
+
organize [ CreateProductInteractor, CreateInvoiceInteractor ]
|
53
84
|
end
|
54
85
|
```
|
55
86
|
|
56
|
-
|
57
|
-
Then you will have to redefine all the methods you need. Each action of the controller is mapped to a method.
|
58
|
-
The return of the method will be passed to respond_with.
|
59
|
-
You can pass extra options to respond_with by defining @options, default to blank hash {}.
|
60
|
-
|
61
|
-
Sometimes, the ActiveRecord models grow to much. It start to handle all kinds of logic. To make things simple,
|
62
|
-
it should only concern about database access. To clean it, use the Zertico::Accessor. It is a wrapper that will
|
63
|
-
pass all methods to the object unless the ones you overwrite. This way, is easy to start develop better models.
|
87
|
+
In this example, it something goes wrong with the Invoice Creation, it will rollback the Product Creation.
|
64
88
|
|
65
|
-
|
66
|
-
It means, better and simple tests, without depend on rails and any other external logic. =D
|
89
|
+
### Zertico::Responder
|
67
90
|
|
68
|
-
|
91
|
+
`Zertico::Responder` its a custom Rails Responder with [pjax](https://github.com/defunkt/jquery-pjax) support and an
|
92
|
+
option to force a redirect no matter what.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
class ApplicationResponder < ActionController::Responder
|
96
|
+
# custom responder behavior implemented by [responders](https://github.com/plataformatec/responders)
|
97
|
+
include Responders::FlashResponder
|
98
|
+
include Responders::HttpCacheResponder
|
99
|
+
include Responders::CollectionResponder
|
100
|
+
|
101
|
+
# add this line to get the Zertico::Responder behavior
|
102
|
+
include Zertico::Responder
|
103
|
+
end
|
104
|
+
```
|
69
105
|
|
70
|
-
|
71
|
-
have the same name of your controller, without the 'Controller' substring. The Service need to replace the
|
72
|
-
'Controller' substring with 'Service' like:
|
106
|
+
You will also need to define your custom Responder inside your ApplicationController:
|
73
107
|
|
74
108
|
```ruby
|
75
|
-
class
|
109
|
+
class ApplicationController < ActionController::Base
|
110
|
+
self.responder = ApplicationResponder
|
111
|
+
|
112
|
+
respond_to :html
|
76
113
|
end
|
114
|
+
```
|
77
115
|
|
78
|
-
|
79
|
-
include Zertico::Service
|
80
|
-
end
|
116
|
+
### Zertico::Service
|
81
117
|
|
82
|
-
|
118
|
+
`Zertico::Service` gives more flexibility to the `Zertico::Controller`. When using `Zertico::Controller` your controllers
|
119
|
+
will try to find a module with the same name as your controller. If it can't find, it will include `Zertico::Service`.
|
120
|
+
If you define a service, you can define which class to use on that controller and even more.
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
class AdminController < ApplicationController
|
83
124
|
end
|
84
125
|
|
85
|
-
|
126
|
+
module UsersService
|
127
|
+
include Zertico::Service
|
128
|
+
|
129
|
+
def interface_class
|
130
|
+
User
|
131
|
+
end
|
86
132
|
end
|
87
133
|
```
|
88
134
|
|
89
|
-
|
135
|
+
In the example above, the controller will use the model User instead of the model Admin he would have guessed.
|
136
|
+
|
137
|
+
### Extra Tips
|
138
|
+
|
139
|
+
Its is a good idea to separate each of the patterns you use in his own folder. If you choose to use all patterns here,
|
140
|
+
you would have this:
|
141
|
+
|
142
|
+
app/
|
143
|
+
controllers/
|
144
|
+
delegators/
|
145
|
+
interactors/
|
146
|
+
organizers/
|
147
|
+
responders/
|
148
|
+
services/
|
149
|
+
|
150
|
+
## Thanks
|
151
|
+
|
152
|
+
The `Interactor` and `Organizer` idea was taken from [interactor](https://github.com/collectiveidea/interactor) by
|
153
|
+
[collectiveidea](https://github.com/collectiveidea).
|
90
154
|
|
91
155
|
## Mantainers
|
92
156
|
|
data/lib/zertico.rb
CHANGED
@@ -2,8 +2,12 @@ require 'zertico/version'
|
|
2
2
|
require 'active_support/core_ext/string'
|
3
3
|
|
4
4
|
module Zertico
|
5
|
-
autoload :Controller, 'zertico/controller'
|
6
|
-
autoload :Service, 'zertico/service'
|
7
5
|
autoload :Accessor, 'zertico/accessor'
|
6
|
+
autoload :Controller, 'zertico/controller'
|
7
|
+
autoload :Delegator, 'zertico/delegator'
|
8
|
+
autoload :Exceptions, 'zertico/exceptions'
|
9
|
+
autoload :Interactor, 'zertico/interactor'
|
10
|
+
autoload :Organizer, 'zertico/organizer'
|
8
11
|
autoload :Responder, 'zertico/responder'
|
12
|
+
autoload :Service, 'zertico/service'
|
9
13
|
end
|
data/lib/zertico/accessor.rb
CHANGED
@@ -1,56 +1,8 @@
|
|
1
1
|
module Zertico
|
2
|
-
class Accessor
|
2
|
+
class Accessor < Delegator
|
3
3
|
def initialize(object)
|
4
|
-
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.find(id)
|
8
|
-
new(interface_class.find(id))
|
9
|
-
end
|
10
|
-
|
11
|
-
def interface
|
12
|
-
instance_variable_get("@#{interface_name}")
|
13
|
-
end
|
14
|
-
|
15
|
-
def method_missing(method_name, *args)
|
16
|
-
if interface.respond_to?(method_name)
|
17
|
-
return interface.send(method_name, *args)
|
18
|
-
end
|
4
|
+
warn "[DEPRECATION] `Zertico::Accessor` is deprecated. Please use `Zertico::Delegator` instead."
|
19
5
|
super
|
20
6
|
end
|
21
|
-
|
22
|
-
if RUBY_VERSION == '1.8.7'
|
23
|
-
def respond_to?(method_name, include_private = false)
|
24
|
-
return true if self.interface.respond_to?(method_name)
|
25
|
-
super
|
26
|
-
end
|
27
|
-
else
|
28
|
-
def respond_to_missing?(method_name, include_private = false)
|
29
|
-
return true if self.interface.respond_to?(method_name)
|
30
|
-
super
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
protected
|
35
|
-
|
36
|
-
def self.interface_name
|
37
|
-
self.interface_class.name.split('::').last.singularize.underscore
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.interface_class
|
41
|
-
begin
|
42
|
-
self.name.chomp('Accessor').constantize
|
43
|
-
rescue NameError
|
44
|
-
self.name.chomp('Accessor').split('::').last.constantize
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def interface_name
|
49
|
-
self.class.interface_name
|
50
|
-
end
|
51
|
-
|
52
|
-
def interface_class
|
53
|
-
self.class.interface_class
|
54
|
-
end
|
55
7
|
end
|
56
8
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
3
|
+
module Zertico
|
4
|
+
class Delegator < SimpleDelegator
|
5
|
+
def self.find(id)
|
6
|
+
new(interface_class.find(id))
|
7
|
+
end
|
8
|
+
|
9
|
+
def interface
|
10
|
+
__getobj__
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def self.interface_name
|
16
|
+
self.interface_class.name.split('::').last.singularize.underscore
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.interface_class
|
20
|
+
begin
|
21
|
+
self.name.chomp('Delegator').constantize
|
22
|
+
rescue NameError
|
23
|
+
self.name.chomp('Delegator').split('::').last.constantize
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def interface_name
|
28
|
+
self.class.interface_name
|
29
|
+
end
|
30
|
+
|
31
|
+
def interface_class
|
32
|
+
self.class.interface_class
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Zertico
|
2
|
+
class Interactor
|
3
|
+
def perform(params)
|
4
|
+
fail!('You should overwrite this method!')
|
5
|
+
end
|
6
|
+
|
7
|
+
def rollback
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def self.instance_name
|
14
|
+
self.class.to_s.chomp('Interactor').split('::').last
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def fail!(message = '')
|
20
|
+
raise Zertico::Exceptions::RollbackException, message
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Zertico
|
2
|
+
module Organizer
|
3
|
+
attr_reader :interactors_classes, :performed
|
4
|
+
|
5
|
+
def organize(interactors)
|
6
|
+
@performed = []
|
7
|
+
@interactors_classes = Array(interactors)
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform(params)
|
11
|
+
@params = params
|
12
|
+
interactors_classes.each do |interactor_class|
|
13
|
+
interactor = interactor_class.new
|
14
|
+
interactor.perform(@params)
|
15
|
+
performed << interactor
|
16
|
+
end
|
17
|
+
true
|
18
|
+
rescue Zertico::Exceptions::RollbackException
|
19
|
+
rollback
|
20
|
+
end
|
21
|
+
|
22
|
+
def rollback
|
23
|
+
performed.map(&:rollback)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/zertico/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
@@ -1,2 +1,2 @@
|
|
1
1
|
class UsersController < Zertico::Controller
|
2
|
-
end
|
2
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zertico::Delegator do
|
4
|
+
let(:user) { User.new }
|
5
|
+
let(:user_delegator) { UserDelegator.new(user) }
|
6
|
+
|
7
|
+
context 'on a namespaced delegator and interface model' do
|
8
|
+
it 'should find the interface model' do
|
9
|
+
Person::ProfileDelegator.send(:interface_class).should == Person::Profile
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should return a valid instance variable name' do
|
13
|
+
Person::ProfileDelegator.send(:interface_name).should == 'profile'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'on a namespaced delegator and non namespaced interface model' do
|
18
|
+
it 'should find the interface model' do
|
19
|
+
Admin::UserDelegator.send(:interface_class).should == User
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should return a valid instance variable name' do
|
23
|
+
Admin::UserDelegator.send(:interface_name).should == 'user'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'on a non namespaced delegator and non namespaced interface model' do
|
28
|
+
it 'should find the interface model' do
|
29
|
+
UserDelegator.send(:interface_class).should == User
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should return a valid instance variable name' do
|
33
|
+
UserDelegator.send(:interface_name).should == 'user'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '.find' do
|
38
|
+
before :each do
|
39
|
+
User.stub(:find => user)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should return an delegator' do
|
43
|
+
UserDelegator.find(3).should be_an_instance_of(UserDelegator)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#interface' do
|
48
|
+
before :each do
|
49
|
+
User.stub(:find => user)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should return the interface object' do
|
53
|
+
UserDelegator.find(3).interface.should == user
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zertico::Organizer do
|
4
|
+
let(:successful_organizer) { BuyProductOrganizer }
|
5
|
+
let(:failed_organizer) { RegisterOrganizer }
|
6
|
+
|
7
|
+
describe '.organize' do
|
8
|
+
it 'should set the interactors to organize' do
|
9
|
+
successful_organizer.interactors_classes.should == [ CreateProductInteractor, CreateInvoiceInteractor ]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.perform' do
|
14
|
+
context 'with success' do
|
15
|
+
it 'should return true' do
|
16
|
+
successful_organizer.perform({}).should be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with failure' do
|
21
|
+
it "should return a mapping with the interactor's rollback results" do
|
22
|
+
failed_organizer.perform({}).should == [true]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe '#rollback' do
|
28
|
+
context 'when it raise an exception' do
|
29
|
+
it "should return a mapping with the interactor's rollback results" do
|
30
|
+
failed_organizer.rollback.should == [true]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/zertico.gemspec
CHANGED
@@ -8,8 +8,9 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Zertico::VERSION
|
9
9
|
gem.authors = ['Paulo Henrique Lopes Ribeiro']
|
10
10
|
gem.email = %w(plribeiro3000@gmail.com)
|
11
|
-
gem.description = %q{
|
12
|
-
gem.summary = %q{
|
11
|
+
gem.description = %q{Collection of Patterns and Tools to increase development speed}
|
12
|
+
gem.summary = %q{Common Patterns used by Zertico}
|
13
|
+
|
13
14
|
gem.license = 'MIT'
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zertico
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Henrique Lopes Ribeiro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description: Collection of Patterns and Tools to increase development speed
|
56
56
|
email:
|
57
57
|
- plribeiro3000@gmail.com
|
58
58
|
executables: []
|
@@ -75,24 +75,39 @@ files:
|
|
75
75
|
- lib/zertico.rb
|
76
76
|
- lib/zertico/accessor.rb
|
77
77
|
- lib/zertico/controller.rb
|
78
|
+
- lib/zertico/delegator.rb
|
79
|
+
- lib/zertico/exceptions.rb
|
80
|
+
- lib/zertico/exceptions/rollback_exception.rb
|
81
|
+
- lib/zertico/interactor.rb
|
82
|
+
- lib/zertico/organizer.rb
|
78
83
|
- lib/zertico/responder.rb
|
79
84
|
- lib/zertico/service.rb
|
80
85
|
- lib/zertico/version.rb
|
81
|
-
- spec/fake_app/admin/
|
82
|
-
- spec/fake_app/
|
83
|
-
- spec/fake_app/
|
84
|
-
- spec/fake_app/
|
85
|
-
- spec/fake_app/
|
86
|
-
- spec/fake_app/
|
87
|
-
- spec/fake_app/
|
88
|
-
- spec/fake_app/
|
89
|
-
- spec/fake_app/
|
90
|
-
- spec/fake_app/
|
91
|
-
- spec/fake_app/
|
92
|
-
- spec/fake_app/
|
86
|
+
- spec/fake_app/controllers/admin/user_controller.rb
|
87
|
+
- spec/fake_app/controllers/profile/profile_controller.rb
|
88
|
+
- spec/fake_app/controllers/user_controller.rb
|
89
|
+
- spec/fake_app/controllers/users_controller.rb
|
90
|
+
- spec/fake_app/delegators/admin/user_delegator.rb
|
91
|
+
- spec/fake_app/delegators/profile/profile_delegator.rb
|
92
|
+
- spec/fake_app/delegators/user_delegator.rb
|
93
|
+
- spec/fake_app/interactors/create_invoice_interactor.rb
|
94
|
+
- spec/fake_app/interactors/create_product_interactor.rb
|
95
|
+
- spec/fake_app/interactors/create_user_interactor.rb
|
96
|
+
- spec/fake_app/interactors/send_welcome_email_interactor.rb
|
97
|
+
- spec/fake_app/interfaces/invoice.rb
|
98
|
+
- spec/fake_app/interfaces/person/profile.rb
|
99
|
+
- spec/fake_app/interfaces/product.rb
|
100
|
+
- spec/fake_app/interfaces/user.rb
|
101
|
+
- spec/fake_app/organizers/buy_product_organizer.rb
|
102
|
+
- spec/fake_app/organizers/register_organizer.rb
|
103
|
+
- spec/fake_app/services/admin/user_service.rb
|
104
|
+
- spec/fake_app/services/person/profile_service.rb
|
105
|
+
- spec/fake_app/services/user_service.rb
|
93
106
|
- spec/spec_helper.rb
|
94
|
-
- spec/zertico/accessor_spec.rb
|
95
107
|
- spec/zertico/controller_spec.rb
|
108
|
+
- spec/zertico/delegator_spec.rb
|
109
|
+
- spec/zertico/interactor_spec.rb
|
110
|
+
- spec/zertico/organizer_spec.rb
|
96
111
|
- spec/zertico/service_spec.rb
|
97
112
|
- zertico.gemspec
|
98
113
|
homepage:
|
@@ -118,25 +133,35 @@ rubyforge_project:
|
|
118
133
|
rubygems_version: 2.2.2
|
119
134
|
signing_key:
|
120
135
|
specification_version: 4
|
121
|
-
summary:
|
136
|
+
summary: Common Patterns used by Zertico
|
122
137
|
test_files:
|
123
138
|
- gemfiles/Gemfile.rails3.1
|
124
139
|
- gemfiles/Gemfile.rails3.2
|
125
140
|
- gemfiles/Gemfile.rails4.0
|
126
141
|
- gemfiles/Gemfile.rails4.1
|
127
|
-
- spec/fake_app/admin/
|
128
|
-
- spec/fake_app/
|
129
|
-
- spec/fake_app/
|
130
|
-
- spec/fake_app/
|
131
|
-
- spec/fake_app/
|
132
|
-
- spec/fake_app/
|
133
|
-
- spec/fake_app/
|
134
|
-
- spec/fake_app/
|
135
|
-
- spec/fake_app/
|
136
|
-
- spec/fake_app/
|
137
|
-
- spec/fake_app/
|
138
|
-
- spec/fake_app/
|
142
|
+
- spec/fake_app/controllers/admin/user_controller.rb
|
143
|
+
- spec/fake_app/controllers/profile/profile_controller.rb
|
144
|
+
- spec/fake_app/controllers/user_controller.rb
|
145
|
+
- spec/fake_app/controllers/users_controller.rb
|
146
|
+
- spec/fake_app/delegators/admin/user_delegator.rb
|
147
|
+
- spec/fake_app/delegators/profile/profile_delegator.rb
|
148
|
+
- spec/fake_app/delegators/user_delegator.rb
|
149
|
+
- spec/fake_app/interactors/create_invoice_interactor.rb
|
150
|
+
- spec/fake_app/interactors/create_product_interactor.rb
|
151
|
+
- spec/fake_app/interactors/create_user_interactor.rb
|
152
|
+
- spec/fake_app/interactors/send_welcome_email_interactor.rb
|
153
|
+
- spec/fake_app/interfaces/invoice.rb
|
154
|
+
- spec/fake_app/interfaces/person/profile.rb
|
155
|
+
- spec/fake_app/interfaces/product.rb
|
156
|
+
- spec/fake_app/interfaces/user.rb
|
157
|
+
- spec/fake_app/organizers/buy_product_organizer.rb
|
158
|
+
- spec/fake_app/organizers/register_organizer.rb
|
159
|
+
- spec/fake_app/services/admin/user_service.rb
|
160
|
+
- spec/fake_app/services/person/profile_service.rb
|
161
|
+
- spec/fake_app/services/user_service.rb
|
139
162
|
- spec/spec_helper.rb
|
140
|
-
- spec/zertico/accessor_spec.rb
|
141
163
|
- spec/zertico/controller_spec.rb
|
164
|
+
- spec/zertico/delegator_spec.rb
|
165
|
+
- spec/zertico/interactor_spec.rb
|
166
|
+
- spec/zertico/organizer_spec.rb
|
142
167
|
- spec/zertico/service_spec.rb
|
data/spec/fake_app/user.rb
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Zertico::Accessor do
|
4
|
-
let(:user) { User.new }
|
5
|
-
let(:user_accessor) { UserAccessor.new(user) }
|
6
|
-
|
7
|
-
context 'on a namespaced accessor and interface model' do
|
8
|
-
it 'should find the interface model' do
|
9
|
-
Person::ProfileAccessor.send(:interface_class).should == Person::Profile
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'should return a valid instance variable name' do
|
13
|
-
Person::ProfileAccessor.send(:interface_name).should == 'profile'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context 'on a namespaced accessor and non namespaced interface model' do
|
18
|
-
it 'should find the interface model' do
|
19
|
-
Admin::UserAccessor.send(:interface_class).should == User
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should return a valid instance variable name' do
|
23
|
-
Admin::UserAccessor.send(:interface_name).should == 'user'
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'on a non namespaced accessor and non namespaced interface model' do
|
28
|
-
it 'should find the interface model' do
|
29
|
-
UserAccessor.send(:interface_class).should == User
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'should return a valid instance variable name' do
|
33
|
-
UserAccessor.send(:interface_name).should == 'user'
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe '.find' do
|
38
|
-
before :each do
|
39
|
-
User.stub(:find => user)
|
40
|
-
UserAccessor.stub(:new => user_accessor)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should return an accessor' do
|
44
|
-
UserAccessor.find(3).should == user_accessor
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '#interface' do
|
49
|
-
before :each do
|
50
|
-
User.stub(:find => user)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should return the interface object' do
|
54
|
-
UserAccessor.find(3).interface.should == user
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '#method_missing' do
|
59
|
-
it 'should pass the method to the interface model if it responds to it' do
|
60
|
-
user_accessor.should respond_to(:full_name)
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|