iugusdk 1.0.0.alpha.1 → 1.0.0.alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/controllers/iugu/account_controller.rb +24 -28
- data/app/controllers/iugu/account_domains_controller.rb +35 -5
- data/app/controllers/iugu/account_roles_controller.rb +2 -5
- data/app/controllers/iugu/account_users_controller.rb +6 -12
- data/app/controllers/iugu/confirmations_controller.rb +1 -0
- data/app/controllers/iugu/invitations_controller.rb +17 -23
- data/app/controllers/iugu/omniauth_callbacks_controller.rb +3 -1
- data/app/controllers/iugu/passwords_controller.rb +1 -0
- data/app/controllers/iugu/registrations_controller.rb +11 -0
- data/app/controllers/iugu/sessions_controller.rb +1 -0
- data/app/controllers/iugu/settings_controller.rb +14 -0
- data/app/mailers/iugu_mailer.rb +2 -2
- data/app/models/account.rb +15 -0
- data/app/models/account_domain.rb +25 -2
- data/app/models/user.rb +19 -3
- data/app/models/user_invitation.rb +15 -2
- data/app/views/iugu/account_domains/index.html.haml +50 -25
- data/app/views/iugu/account_domains/instructions.html.haml +3 -0
- data/app/views/iugu/account_users/index.html.haml +4 -2
- data/app/views/iugu/invitations/new.html.haml +19 -5
- data/app/views/iugu/registrations/new.html.haml +4 -1
- data/app/views/iugu/sessions/new.html.haml +9 -8
- data/app/views/iugu/settings/account.html.haml +31 -23
- data/app/views/iugu/settings/accounts.html.haml +5 -3
- data/app/views/iugu/settings/profile.html.haml +47 -44
- data/app/views/iugu/shared/_links.haml +14 -11
- data/app/views/layouts/settings.html.haml +1 -1
- data/config/initializers/devise.rb +0 -13
- data/config/locales/iugu.en.yml +6 -0
- data/config/locales/iugu.pt-BR.yml +6 -0
- data/config/routes.rb +9 -4
- data/db/migrate/20120725170859_add_api_token_to_account.rb +9 -0
- data/db/migrate/20120803172545_add_guest_to_users.rb +9 -0
- data/lib/iugusdk/controllers/helpers.rb +1 -1
- data/lib/iugusdk/engine.rb +1 -1
- data/lib/iugusdk/iugusdk_base_controller.rb +17 -0
- data/lib/iugusdk/version.rb +1 -1
- data/lib/iugusdk.rb +30 -5
- data/spec/controller_macros.rb +1 -1
- data/spec/controllers/account_controller_spec.rb +26 -45
- data/spec/controllers/account_domains_controller_spec.rb +87 -5
- data/spec/controllers/account_roles_controller_spec.rb +0 -14
- data/spec/controllers/invitations_controller_spec.rb +21 -1
- data/spec/controllers/registration_controller_spec.rb +15 -0
- data/spec/controllers/settings_controller_spec.rb +105 -0
- data/spec/dummy/db/schema.rb +3 -1
- data/spec/dummy/log/development.log +1579 -0
- data/spec/dummy/tmp/cache/assets/C91/3F0/sprockets%2Fcd844928d19e586b4146833b720e7d29 +0 -0
- data/spec/dummy/tmp/cache/assets/CAA/190/sprockets%2Fee7298fdc707d359368983e09687c627 +0 -0
- data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/CE6/A00/sprockets%2F583256e44957e430e1eca9ba1739b6b6 +0 -0
- data/spec/dummy/tmp/cache/assets/CE7/4B0/sprockets%2Fd3774b9099289a36db44caec70813a19 +0 -0
- data/spec/dummy/tmp/cache/assets/CF1/A70/sprockets%2F368a631d9662bcc4891c91f739b7be37 +0 -0
- data/spec/dummy/tmp/cache/assets/CF6/A50/sprockets%2Ff434c1ed5d55916f790cf698832f76b1 +0 -0
- data/spec/dummy/tmp/cache/assets/CFB/F30/sprockets%2F84131db318a2faf415628c1075c32bdd +0 -0
- data/spec/dummy/tmp/cache/assets/D1A/F20/sprockets%2F102cc77ec78847746b1c164edcb9b639 +0 -0
- data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/D3A/D70/sprockets%2Fa3bc2dd9e66062ea36222fc6154827ee +0 -0
- data/spec/dummy/tmp/cache/assets/D46/E20/sprockets%2F1de16fe0c12f9988664ed66a835a6ab0 +0 -0
- data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/D64/F60/sprockets%2F4755d7f5deef0f3212cb7ae30172a33e +0 -0
- data/spec/dummy/tmp/cache/assets/D69/850/sprockets%2F5c160a5a6d1068a17af57ab38affd379 +0 -0
- data/spec/dummy/tmp/cache/assets/D77/1A0/sprockets%2Ff3864fc006a0674b4c977ff5ca5c7d2e +0 -0
- data/spec/dummy/tmp/cache/assets/D77/920/sprockets%2Faf0e746c541e6cf4540db92c87da579c +0 -0
- data/spec/dummy/tmp/cache/assets/D7A/850/sprockets%2Fd1e5bf9f64829d062ed7314af28a4e7e +0 -0
- data/spec/dummy/tmp/cache/assets/D86/3F0/sprockets%2F8f648e11dfcec044b2997b98f619cfa6 +0 -0
- data/spec/dummy/tmp/cache/assets/DA5/130/sprockets%2F7d741fa9ebe86e96fb2bd116ca91234e +0 -0
- data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/DF2/910/sprockets%2F02db4a9e6f91b47261fa5b0eece2ab8b +0 -0
- data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/E25/5A0/sprockets%2F795f5759cf9bc7cde9f8acf8c0ca479f +0 -0
- data/spec/dummy/tmp/cache/assets/E35/0E0/sprockets%2F9f57eaeefd4c9d5efb41c9801e3f1c1a +0 -0
- data/spec/dummy/tmp/cache/sass/e5be18dde92936a4632e65289dad5788ed73dd60/settings.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/default.sassc +0 -0
- data/spec/fabricators/account_domain_fabricator.rb +5 -1
- data/spec/models/account_domain_spec.rb +49 -12
- data/spec/models/account_spec.rb +32 -4
- data/spec/models/user_invitation_spec.rb +23 -1
- data/spec/models/user_spec.rb +76 -0
- data/spec/requests/account_domain_spec.rb +71 -37
- data/spec/requests/account_roles_spec.rb +1 -0
- data/spec/requests/account_spec.rb +65 -3
- data/spec/requests/account_users_spec.rb +1 -0
- data/spec/requests/omniauth_spec.rb +34 -0
- data/spec/requests/settings_spec.rb +4 -4
- data/spec/requests/user_invitation_spec.rb +32 -1
- data/spec/requests/user_spec.rb +13 -0
- metadata +126 -70
- data/lib/iugusdk/locale_filter.rb +0 -12
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Iugu::AccountDomainsController do
|
|
4
|
+
before(:each) do
|
|
5
|
+
IuguSDK::enable_custom_domain = true
|
|
6
|
+
end
|
|
7
|
+
|
|
4
8
|
context "index" do
|
|
5
9
|
login_as_user
|
|
6
10
|
before(:each) do
|
|
7
11
|
@account = @user.accounts.first
|
|
8
|
-
@account.account_domains <<
|
|
12
|
+
@account.account_domains << @domain = AccountDomain.create(:url => "controller.test.test")
|
|
9
13
|
get :index, :account_id => @account.id
|
|
10
14
|
end
|
|
11
15
|
|
|
@@ -35,7 +39,7 @@ describe Iugu::AccountDomainsController do
|
|
|
35
39
|
login_as_user
|
|
36
40
|
before(:each) do
|
|
37
41
|
@account = @user.accounts.first
|
|
38
|
-
@account.account_domains <<
|
|
42
|
+
@account.account_domains << AccountDomain.create(:url => "destroy.test.net" )
|
|
39
43
|
@domain = @account.account_domains.last
|
|
40
44
|
end
|
|
41
45
|
|
|
@@ -66,7 +70,7 @@ describe Iugu::AccountDomainsController do
|
|
|
66
70
|
login_as_user
|
|
67
71
|
before(:each) do
|
|
68
72
|
@account = @user.accounts.first
|
|
69
|
-
@account.account_domains <<
|
|
73
|
+
@account.account_domains << AccountDomain.create(:url => "instructions.test.net" )
|
|
70
74
|
@domain = @account.account_domains.last
|
|
71
75
|
end
|
|
72
76
|
|
|
@@ -94,7 +98,7 @@ describe Iugu::AccountDomainsController do
|
|
|
94
98
|
login_as_user
|
|
95
99
|
before(:each) do
|
|
96
100
|
@account = @user.accounts.first
|
|
97
|
-
@account.account_domains <<
|
|
101
|
+
@account.account_domains << AccountDomain.create(:url => "verify.test.net" )
|
|
98
102
|
@domain = @account.account_domains.last
|
|
99
103
|
end
|
|
100
104
|
|
|
@@ -141,7 +145,7 @@ describe Iugu::AccountDomainsController do
|
|
|
141
145
|
login_as_user
|
|
142
146
|
before(:each) do
|
|
143
147
|
@account = @user.accounts.first
|
|
144
|
-
@account.account_domains <<
|
|
148
|
+
@account.account_domains << AccountDomain.create(:url => "primary.test.net" )
|
|
145
149
|
@domain = @account.account_domains.last
|
|
146
150
|
end
|
|
147
151
|
|
|
@@ -168,4 +172,82 @@ describe Iugu::AccountDomainsController do
|
|
|
168
172
|
end
|
|
169
173
|
|
|
170
174
|
end
|
|
175
|
+
|
|
176
|
+
context "update_subdomain" do
|
|
177
|
+
login_as_user
|
|
178
|
+
before(:each) do
|
|
179
|
+
@account = @user.accounts.first
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
context "when enable_subdomain == true" do
|
|
183
|
+
before(:each) do
|
|
184
|
+
IuguSDK::enable_subdomain = true
|
|
185
|
+
put :update_subdomain, :account_id => @account.id, :account => {:subdomain => "subdomain"}
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
it { response.should redirect_to account_domains_index_path(@account.id) }
|
|
189
|
+
|
|
190
|
+
it { flash.now[:notice].should == I18n.t("iugu.notices.subdomain_updated") }
|
|
191
|
+
|
|
192
|
+
context "and update isnt successfull" do
|
|
193
|
+
before(:each) do
|
|
194
|
+
stub.any_instance_of(Account).update_attributes { false }
|
|
195
|
+
put :update_subdomain, :account_id => @account.id, :account => {:subdomain => "subdomain"}
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
it { response.should render_template :index }
|
|
199
|
+
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
context "when enable_subdomain == false" do
|
|
204
|
+
before(:each) do
|
|
205
|
+
IuguSDK::enable_subdomain = false
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
it 'should raise RoutingError' do
|
|
209
|
+
lambda {
|
|
210
|
+
put :update_subdomain, :account_id => @account.id, :account => {:subdomain => "subdomain"}
|
|
211
|
+
}.should raise_error ActionController::RoutingError
|
|
212
|
+
end
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
|
|
216
|
+
context "when enable_custom_domain == false" do
|
|
217
|
+
login_as_user
|
|
218
|
+
before(:each) do
|
|
219
|
+
@account = @user.accounts.first
|
|
220
|
+
IuguSDK::enable_custom_domain = false
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it 'create method should raise RoutingError' do
|
|
224
|
+
lambda {
|
|
225
|
+
post :create, :account_id => @account.id, :account_domain => { :url => "new.test.net" }
|
|
226
|
+
}.should raise_error ActionController::RoutingError
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
it 'destroy method should raise RoutingError' do
|
|
230
|
+
lambda {
|
|
231
|
+
delete :destroy, :account_id => @account.id, :domain_id => 1
|
|
232
|
+
}.should raise_error ActionController::RoutingError
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
context "when enable_custom_domain == false && enable_subdomain == false" do
|
|
238
|
+
login_as_user
|
|
239
|
+
before(:each) do
|
|
240
|
+
@account = @user.accounts.first
|
|
241
|
+
IuguSDK::enable_custom_domain = false
|
|
242
|
+
IuguSDK::enable_subdomain = false
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
it 'index method should raise RoutingError' do
|
|
246
|
+
lambda {
|
|
247
|
+
get :index, :account_id => @account.id
|
|
248
|
+
}.should raise_error ActionController::RoutingError
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
end
|
|
252
|
+
|
|
171
253
|
end
|
|
@@ -18,20 +18,6 @@ describe Iugu::AccountRolesController do
|
|
|
18
18
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
context "when current_user do not owns the account" do
|
|
22
|
-
|
|
23
|
-
before(:each) do
|
|
24
|
-
@current_account_user = @user.account_users.first
|
|
25
|
-
@account = @current_account_user.account
|
|
26
|
-
@account.account_users << Fabricate(:account_user) { user Fabricate(:user) { email "notowner@account.test" } }
|
|
27
|
-
@current_account_user.set_roles(["user"])
|
|
28
|
-
get :edit, :id => @current_account_user.account_id, :user_id => @current_account_user.user_id
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
it { response.should_not render_template "iugu/account_roles/edit" }
|
|
32
|
-
it { response.should_not be_success }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
21
|
end
|
|
36
22
|
|
|
37
23
|
context "update" do
|
|
@@ -42,6 +42,13 @@ describe Iugu::InvitationsController do
|
|
|
42
42
|
it 'should create an invite' do
|
|
43
43
|
UserInvitation.last.email.should == "create@controller.teste"
|
|
44
44
|
end
|
|
45
|
+
|
|
46
|
+
it 'should render new if create isnt successfull' do
|
|
47
|
+
stub(UserInvitation).create {UserInvitation.new}
|
|
48
|
+
post :create, :account_id => @account.id, :user_invitation => {:email => "create@controller.teste"}
|
|
49
|
+
response.should render_template :new
|
|
50
|
+
end
|
|
51
|
+
|
|
45
52
|
|
|
46
53
|
end
|
|
47
54
|
|
|
@@ -77,7 +84,8 @@ describe Iugu::InvitationsController do
|
|
|
77
84
|
before(:each) do
|
|
78
85
|
@account = Fabricate(:account)
|
|
79
86
|
@user_invitation = Fabricate(:user_invitation)
|
|
80
|
-
@user_invitation.
|
|
87
|
+
@user_invitation.account = @account
|
|
88
|
+
@user_invitation.save
|
|
81
89
|
end
|
|
82
90
|
|
|
83
91
|
context "when token is not valid" do
|
|
@@ -98,5 +106,17 @@ describe Iugu::InvitationsController do
|
|
|
98
106
|
it { response.should redirect_to root_path }
|
|
99
107
|
|
|
100
108
|
end
|
|
109
|
+
|
|
110
|
+
context "when user is already member of the account" do
|
|
111
|
+
before(:each) do
|
|
112
|
+
@account.users << @user
|
|
113
|
+
get :update, :invitation_token => @user_invitation.id.to_s + @user_invitation.token
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
it { response.should redirect_to root_path }
|
|
117
|
+
|
|
118
|
+
it { flash.now[:notice].should == I18n.t("iugu.notices.you_are_already_member_of_this_account") }
|
|
119
|
+
|
|
120
|
+
end
|
|
101
121
|
end
|
|
102
122
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Iugu::RegistrationsController do
|
|
4
|
+
|
|
5
|
+
context "try first" do
|
|
6
|
+
before(:each) do
|
|
7
|
+
@request.env["devise.mapping"] = Devise.mappings[:user]
|
|
8
|
+
post :try_first
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it { flash.now[:notice].should == I18n.t("iugu.notices.guest_login") }
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
@@ -12,3 +12,108 @@ describe Iugu::SettingsController do
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
end
|
|
15
|
+
|
|
16
|
+
class StubPermissionsController < Iugu::SettingsController
|
|
17
|
+
|
|
18
|
+
before_filter(:only => :stub){ |c| c.must_be [:owner, :admin], :id }
|
|
19
|
+
before_filter(:only => :stub2){ |c| c.must_be :owner, :id }
|
|
20
|
+
|
|
21
|
+
def stub
|
|
22
|
+
render :text => "true", :status => 200
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def stub2
|
|
26
|
+
render :text => "true", :status => 200
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
describe StubPermissionsController do
|
|
33
|
+
|
|
34
|
+
def with_stub_routing
|
|
35
|
+
with_routing do |map|
|
|
36
|
+
map.draw do
|
|
37
|
+
match '/stub/account/permissions/stub' => 'stub_permissions#stub'
|
|
38
|
+
match '/stub/account/permissions/stub2' => 'stub_permissions#stub2'
|
|
39
|
+
end
|
|
40
|
+
yield
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
login_as_user
|
|
45
|
+
|
|
46
|
+
before(:each) do
|
|
47
|
+
@user2 = Fabricate(:user, :email => "user2@email.email")
|
|
48
|
+
@account = @user.accounts.first
|
|
49
|
+
@account.users << @user2
|
|
50
|
+
@account_user = AccountUser.find_by_user_id_and_account_id(@user.id, @account.id)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
context "when user have permissions" do
|
|
54
|
+
before(:each) do
|
|
55
|
+
@account_user.set_roles [ "owner" ]
|
|
56
|
+
with_stub_routing do
|
|
57
|
+
get :stub, :id => @account.id
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'stub' do
|
|
62
|
+
with_stub_routing do
|
|
63
|
+
get :stub, :id => @account.id
|
|
64
|
+
end
|
|
65
|
+
response.should be_success
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'should grant access to more than one role' do
|
|
69
|
+
@account_user.set_roles [ "admin" ]
|
|
70
|
+
with_stub_routing do
|
|
71
|
+
get :stub, :id => @account.id
|
|
72
|
+
end
|
|
73
|
+
response.should be_success
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'stub2' do
|
|
77
|
+
with_stub_routing do
|
|
78
|
+
get :stub2, :id => @account.id
|
|
79
|
+
end
|
|
80
|
+
response.should be_success
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "when user dont have permissions" do
|
|
86
|
+
before(:each) do
|
|
87
|
+
@account_user.set_roles [ "user" ]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'stub should raise routing error' do
|
|
91
|
+
lambda {
|
|
92
|
+
with_stub_routing do
|
|
93
|
+
get :stub, :id => @account.id
|
|
94
|
+
end
|
|
95
|
+
}.should raise_error ActionController::RoutingError
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'stub2 should raise routing error' do
|
|
99
|
+
@account_user.set_roles [ "admin" ]
|
|
100
|
+
lambda {
|
|
101
|
+
with_stub_routing do
|
|
102
|
+
get :stub2, :id => @account.id
|
|
103
|
+
end
|
|
104
|
+
}.should raise_error ActionController::RoutingError
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
context "when account user do not exist" do
|
|
110
|
+
it 'should raise routing error' do
|
|
111
|
+
lambda {
|
|
112
|
+
with_stub_routing do
|
|
113
|
+
get :stub, :id => 231213231231312312341
|
|
114
|
+
end
|
|
115
|
+
}.should raise_error ActionController::RoutingError
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end
|
data/spec/dummy/db/schema.rb
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
#
|
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
|
13
13
|
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
|
14
|
+
ActiveRecord::Schema.define(:version => 20120803172545) do
|
|
15
15
|
|
|
16
16
|
create_table "account_domains", :force => true do |t|
|
|
17
17
|
t.integer "account_id"
|
|
@@ -36,6 +36,7 @@ ActiveRecord::Schema.define(:version => 20120719162426) do
|
|
|
36
36
|
t.string "name"
|
|
37
37
|
t.integer "subscription_id"
|
|
38
38
|
t.string "subdomain"
|
|
39
|
+
t.string "api_token"
|
|
39
40
|
end
|
|
40
41
|
|
|
41
42
|
create_table "delayed_jobs", :force => true do |t|
|
|
@@ -86,6 +87,7 @@ ActiveRecord::Schema.define(:version => 20120719162426) do
|
|
|
86
87
|
t.date "birthdate"
|
|
87
88
|
t.string "name"
|
|
88
89
|
t.string "locale"
|
|
90
|
+
t.boolean "guest"
|
|
89
91
|
end
|
|
90
92
|
|
|
91
93
|
add_index "users", ["confirmation_token"], :name => "index_users_on_confirmation_token", :unique => true
|