iugusdk 1.0.0.alpha.0

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.
Files changed (207) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +3 -0
  3. data/Rakefile +39 -0
  4. data/app/assets/images/application_logo.png +0 -0
  5. data/app/assets/javascripts/settings.js +10 -0
  6. data/app/assets/javascripts/settings_code.js.coffee.erb +0 -0
  7. data/app/assets/stylesheets/settings.sass +120 -0
  8. data/app/controllers/iugu/account_controller.rb +63 -0
  9. data/app/controllers/iugu/account_domains_controller.rb +64 -0
  10. data/app/controllers/iugu/account_roles_controller.rb +20 -0
  11. data/app/controllers/iugu/account_settings_controller.rb +17 -0
  12. data/app/controllers/iugu/account_users_controller.rb +43 -0
  13. data/app/controllers/iugu/application_domain_controller.rb +11 -0
  14. data/app/controllers/iugu/confirmations_controller.rb +2 -0
  15. data/app/controllers/iugu/invitations_controller.rb +49 -0
  16. data/app/controllers/iugu/omniauth_callbacks_controller.rb +23 -0
  17. data/app/controllers/iugu/passwords_controller.rb +2 -0
  18. data/app/controllers/iugu/profile_controller.rb +44 -0
  19. data/app/controllers/iugu/registrations_controller.rb +3 -0
  20. data/app/controllers/iugu/sessions_controller.rb +2 -0
  21. data/app/controllers/iugu/settings_controller.rb +11 -0
  22. data/app/controllers/iugu/unlocks_controller.rb +2 -0
  23. data/app/mailers/iugu_mailer.rb +16 -0
  24. data/app/models/account.rb +53 -0
  25. data/app/models/account_domain.rb +69 -0
  26. data/app/models/account_role.rb +24 -0
  27. data/app/models/account_user.rb +55 -0
  28. data/app/models/available_language.rb +10 -0
  29. data/app/models/social_account.rb +14 -0
  30. data/app/models/user.rb +107 -0
  31. data/app/models/user_invitation.rb +39 -0
  32. data/app/validators/email_validator.rb +17 -0
  33. data/app/views/iugu-old/account_settings.html.haml +17 -0
  34. data/app/views/iugu-old/login.html.haml +28 -0
  35. data/app/views/iugu-old/mails/confirmation_instructions.html.erb +5 -0
  36. data/app/views/iugu-old/mails/reset_password_instructions.html.erb +8 -0
  37. data/app/views/iugu-old/mails/unlock_instructions.html.erb +7 -0
  38. data/app/views/iugu-old/profile_settings.html.haml +76 -0
  39. data/app/views/iugu-old/signup.html.haml +36 -0
  40. data/app/views/iugu/account_domains/index.html.haml +33 -0
  41. data/app/views/iugu/account_domains/instructions.html.haml +0 -0
  42. data/app/views/iugu/account_roles/edit.html.haml +17 -0
  43. data/app/views/iugu/account_roles/update.html.haml +0 -0
  44. data/app/views/iugu/account_users/index.html.haml +23 -0
  45. data/app/views/iugu/account_users/view.html.haml +0 -0
  46. data/app/views/iugu/confirmations/new.html.haml +8 -0
  47. data/app/views/iugu/invitations/edit.html.haml +8 -0
  48. data/app/views/iugu/invitations/new.html.haml +13 -0
  49. data/app/views/iugu/mailer/confirmation_instructions.html.haml +4 -0
  50. data/app/views/iugu/mailer/invitation.html.haml +1 -0
  51. data/app/views/iugu/mailer/reset_password_instructions.html.haml +4 -0
  52. data/app/views/iugu/mailer/unlock_instructions.html.haml +5 -0
  53. data/app/views/iugu/passwords/edit.html.haml +11 -0
  54. data/app/views/iugu/passwords/new.html.haml +8 -0
  55. data/app/views/iugu/registrations/edit.html.haml +15 -0
  56. data/app/views/iugu/registrations/new.html.haml +11 -0
  57. data/app/views/iugu/sessions/new.html.haml +9 -0
  58. data/app/views/iugu/settings/account.html.haml +48 -0
  59. data/app/views/iugu/settings/accounts.html.haml +33 -0
  60. data/app/views/iugu/settings/profile.html.haml +96 -0
  61. data/app/views/iugu/shared/_links.haml +19 -0
  62. data/app/views/iugu/unlocks/new.html.haml +8 -0
  63. data/app/views/layouts/settings.html.haml +46 -0
  64. data/config/initializers/account_roles.rb +5 -0
  65. data/config/initializers/devise.rb +242 -0
  66. data/config/initializers/social_accounts.rb +16 -0
  67. data/config/locales/devise.en.yml +57 -0
  68. data/config/locales/devise.pt-BR.yml +55 -0
  69. data/config/locales/iugu.en.yml +73 -0
  70. data/config/locales/iugu.pt-BR.yml +73 -0
  71. data/config/routes.rb +77 -0
  72. data/db/migrate/20120528164634_create_account.rb +11 -0
  73. data/db/migrate/20120529134109_add_devise_to_users.rb +53 -0
  74. data/db/migrate/20120529162901_add_birthdate_and_name_to_user.rb +12 -0
  75. data/db/migrate/20120529174755_add_name_and_subscription_id_and_user_id_to_account.rb +13 -0
  76. data/db/migrate/20120529180814_create_account_users.rb +12 -0
  77. data/db/migrate/20120530114709_remove_user_id_from_accounts.rb +9 -0
  78. data/db/migrate/20120531171438_create_account_roles.rb +12 -0
  79. data/db/migrate/20120604131034_add_locale_to_user.rb +9 -0
  80. data/db/migrate/20120605142527_create_social_account.rb +15 -0
  81. data/db/migrate/20120612141130_set_locale.rb +6 -0
  82. data/db/migrate/20120613173114_remove_unique_from_user_email.rb +11 -0
  83. data/db/migrate/20120615180728_create_delayed_jobs.rb +22 -0
  84. data/db/migrate/20120629154429_create_user_invitations.rb +14 -0
  85. data/db/migrate/20120629195345_add_token_to_user_invitations.rb +8 -0
  86. data/db/migrate/20120705202827_add_roles_to_user_invitations.rb +8 -0
  87. data/db/migrate/20120716145846_create_account_domain.rb +14 -0
  88. data/db/migrate/20120719162426_add_subdomain_to_account.rb +9 -0
  89. data/lib/iugusdk.rb +73 -0
  90. data/lib/iugusdk/controllers/helpers.rb +45 -0
  91. data/lib/iugusdk/engine.rb +13 -0
  92. data/lib/iugusdk/locale_filter.rb +12 -0
  93. data/lib/iugusdk/root_tenancy_url.rb +22 -0
  94. data/lib/iugusdk/valid_tenancy_urls.rb +27 -0
  95. data/lib/iugusdk/version.rb +3 -0
  96. data/lib/tasks/iugusdk_tasks.rake +4 -0
  97. data/spec/controller_macros.rb +41 -0
  98. data/spec/controllers/account_controller_spec.rb +155 -0
  99. data/spec/controllers/account_domains_controller_spec.rb +173 -0
  100. data/spec/controllers/account_roles_controller_spec.rb +48 -0
  101. data/spec/controllers/account_settings_controller_spec.rb +42 -0
  102. data/spec/controllers/account_users_controller_spec.rb +145 -0
  103. data/spec/controllers/application_domain_controller_spec.rb +29 -0
  104. data/spec/controllers/invitations_controller_spec.rb +102 -0
  105. data/spec/controllers/profile_controller_spec.rb +125 -0
  106. data/spec/controllers/settings_controller_spec.rb +14 -0
  107. data/spec/dummy/Rakefile +7 -0
  108. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  109. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  110. data/spec/dummy/app/assets/stylesheets/default.sass +111 -0
  111. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  112. data/spec/dummy/app/controllers/dashboard_controller.rb +8 -0
  113. data/spec/dummy/app/controllers/my_dummy_controller.rb +9 -0
  114. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  115. data/spec/dummy/app/views/dashboard/index.html.haml +5 -0
  116. data/spec/dummy/app/views/dashboard/splash.html.haml +10 -0
  117. data/spec/dummy/app/views/layouts/application.html.erb +29 -0
  118. data/spec/dummy/app/views/layouts/dummy.html.erb +22 -0
  119. data/spec/dummy/app/views/my_dummy/index.html.haml +5 -0
  120. data/spec/dummy/config.ru +4 -0
  121. data/spec/dummy/config/account_roles.yml +3 -0
  122. data/spec/dummy/config/application.rb +66 -0
  123. data/spec/dummy/config/boot.rb +10 -0
  124. data/spec/dummy/config/database.yml +37 -0
  125. data/spec/dummy/config/environment.rb +5 -0
  126. data/spec/dummy/config/environments/development.rb +37 -0
  127. data/spec/dummy/config/environments/production.rb +60 -0
  128. data/spec/dummy/config/environments/test.rb +40 -0
  129. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  130. data/spec/dummy/config/initializers/inflections.rb +10 -0
  131. data/spec/dummy/config/initializers/iugusdk.rb +4 -0
  132. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  133. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  134. data/spec/dummy/config/initializers/session_store.rb +8 -0
  135. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  136. data/spec/dummy/config/locales/en.yml +5 -0
  137. data/spec/dummy/config/routes.rb +69 -0
  138. data/spec/dummy/config/social_accounts.yml +6 -0
  139. data/spec/dummy/db/schema.rb +95 -0
  140. data/spec/dummy/public/404.html +26 -0
  141. data/spec/dummy/public/422.html +26 -0
  142. data/spec/dummy/public/500.html +26 -0
  143. data/spec/dummy/public/favicon.ico +0 -0
  144. data/spec/dummy/script/rails +6 -0
  145. data/spec/dummy/tmp/cache/sass/1f198e4a81e57d6c86c6fff1f0e13592b233ebc2/prettify.cssc +0 -0
  146. data/spec/dummy/tmp/cache/sass/40796b6ca2cf9112b889007328d8a4c5fdc634d8/_css3.scssc +0 -0
  147. data/spec/dummy/tmp/cache/sass/40796b6ca2cf9112b889007328d8a4c5fdc634d8/_support.scssc +0 -0
  148. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/components.sassc +0 -0
  149. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/iugu-ux.sassc +0 -0
  150. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/mixins.sassc +0 -0
  151. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/reset.sassc +0 -0
  152. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/typography.sassc +0 -0
  153. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/utilities.sassc +0 -0
  154. data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/variables.sassc +0 -0
  155. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_appearance.scssc +0 -0
  156. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-clip.scssc +0 -0
  157. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-origin.scssc +0 -0
  158. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-size.scssc +0 -0
  159. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_border-radius.scssc +0 -0
  160. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box-shadow.scssc +0 -0
  161. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box-sizing.scssc +0 -0
  162. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box.scssc +0 -0
  163. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_columns.scssc +0 -0
  164. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_font-face.scssc +0 -0
  165. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_images.scssc +0 -0
  166. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_inline-block.scssc +0 -0
  167. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_opacity.scssc +0 -0
  168. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_shared.scssc +0 -0
  169. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_text-shadow.scssc +0 -0
  170. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_transform.scssc +0 -0
  171. data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_transition.scssc +0 -0
  172. data/spec/dummy/tmp/cache/sass/9da4e62a062dae83baa33f29455be2ba30cf5dce/_sprites.scssc +0 -0
  173. data/spec/dummy/tmp/cache/sass/db2a23483187bf5625185da2d6f47de2a6de4989/_base.scssc +0 -0
  174. data/spec/dummy/tmp/cache/sass/db2a23483187bf5625185da2d6f47de2a6de4989/_sprite-img.scssc +0 -0
  175. data/spec/dummy/tmp/cache/sass/e5be18dde92936a4632e65289dad5788ed73dd60/base_settings.sassc +0 -0
  176. data/spec/dummy/tmp/cache/sass/e5be18dde92936a4632e65289dad5788ed73dd60/settings.sassc +0 -0
  177. data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/application.sassc +0 -0
  178. data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/base_settings.sassc +0 -0
  179. data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/default.sassc +0 -0
  180. data/spec/dummy/tmp/cache/sass/eab9c0816f626278a6731ce2928de6fdbe99322b/_hacks.scssc +0 -0
  181. data/spec/dummy/tmp/restart.txt +0 -0
  182. data/spec/fabricators/account_domain_fabricator.rb +4 -0
  183. data/spec/fabricators/account_fabricator.rb +4 -0
  184. data/spec/fabricators/account_role_fabricator.rb +3 -0
  185. data/spec/fabricators/account_user_fabricator.rb +4 -0
  186. data/spec/fabricators/social_account_fabricator.rb +10 -0
  187. data/spec/fabricators/user_fabricator.rb +10 -0
  188. data/spec/fabricators/user_invitation_fabricator.rb +4 -0
  189. data/spec/mailers/iugu_mailer_spec.rb +22 -0
  190. data/spec/models/account_domain_spec.rb +111 -0
  191. data/spec/models/account_role_spec.rb +24 -0
  192. data/spec/models/account_spec.rb +155 -0
  193. data/spec/models/account_user_spec.rb +158 -0
  194. data/spec/models/social_account_spec.rb +36 -0
  195. data/spec/models/user_invitation_spec.rb +92 -0
  196. data/spec/models/user_spec.rb +187 -0
  197. data/spec/requests/account_domain_spec.rb +77 -0
  198. data/spec/requests/account_roles_spec.rb +45 -0
  199. data/spec/requests/account_spec.rb +97 -0
  200. data/spec/requests/account_users_spec.rb +129 -0
  201. data/spec/requests/omniauth_spec.rb +79 -0
  202. data/spec/requests/settings_spec.rb +53 -0
  203. data/spec/requests/user_invitation_spec.rb +40 -0
  204. data/spec/requests/user_spec.rb +34 -0
  205. data/spec/spec_helper.rb +116 -0
  206. data/spec/validators/email_validator_spec.rb +21 -0
  207. metadata +729 -0
@@ -0,0 +1,173 @@
1
+ require 'spec_helper'
2
+
3
+ describe Iugu::AccountDomainsController do
4
+ context "index" do
5
+ login_as_user
6
+ before(:each) do
7
+ @account = @user.accounts.first
8
+ @account.account_domains << Fabricate(:account_domain)
9
+ get :index, :account_id => @account.id
10
+ end
11
+
12
+ it { response.should render_template "iugu/account_domains/index" }
13
+ end
14
+
15
+ context "create" do
16
+ login_as_user
17
+ before(:each) do
18
+ @account = @user.accounts.first
19
+ post :create, :account_id => @account.id, :account_domain => { :url => "new.test.net" }
20
+ end
21
+
22
+ it { response.should redirect_to account_domains_index_path(@account.id) }
23
+
24
+ it { flash.now[:notice].should == I18n.t("iugu.notices.domain_created") }
25
+
26
+ context "without required fields" do
27
+ before(:each) do
28
+ post :create, :account_id => @account.id, :account_domain => {}
29
+ end
30
+
31
+ it { response.should render_template 'iugu/account_domains/index' }
32
+
33
+ end
34
+ end
35
+
36
+ context "destroy" do
37
+ login_as_user
38
+ before(:each) do
39
+ @account = @user.accounts.first
40
+ @account.account_domains << Fabricate(:account_domain){ url "destroy.test.net" }
41
+ @domain = @account.account_domains.last
42
+ end
43
+
44
+ context "when using a valid id" do
45
+ before(:each) do
46
+ delete :destroy, :account_id => @account.id, :domain_id => @domain.id
47
+ end
48
+
49
+ it { response.should redirect_to account_domains_index_path(@account.id) }
50
+
51
+ it { flash.now[:notice].should == I18n.t("iugu.notices.domain_destroyed") }
52
+
53
+ end
54
+
55
+ context "when using an invalid id" do
56
+ before(:each) do
57
+ delete :destroy, :account_id => @account.id, :domain_id => 1273816283761238716
58
+ end
59
+
60
+ it { response.should redirect_to account_domains_index_path(@account.id) }
61
+
62
+ it { flash.now[:notice].should == I18n.t("iugu.notices.domain_not_found") }
63
+
64
+ end
65
+ end
66
+
67
+ context "instructions" do
68
+ login_as_user
69
+ before(:each) do
70
+ @account = @user.accounts.first
71
+ @account.account_domains << Fabricate(:account_domain){ url "instructions.test.net" }
72
+ @domain = @account.account_domains.last
73
+ end
74
+
75
+ context "when using a valid id" do
76
+ before(:each) do
77
+ get :instructions, :account_id => @account.id, :domain_id => @domain.id
78
+ end
79
+
80
+ it { response.should render_template "iugu/account_domains/instructions" }
81
+ end
82
+
83
+ context "when using an invalid id" do
84
+ before(:each) do
85
+ get :instructions, :account_id => @account.id, :domain_id => 1209371923812238
86
+ end
87
+
88
+ it { response.should redirect_to account_domains_index_path(@account.id) }
89
+
90
+ it { flash.now[:notice].should == I18n.t("iugu.notices.domain_not_found") }
91
+
92
+ end
93
+ end
94
+
95
+ context "verify" do
96
+ login_as_user
97
+ before(:each) do
98
+ @account = @user.accounts.first
99
+ @account.account_domains << Fabricate(:account_domain){ url "verify.test.net" }
100
+ @domain = @account.account_domains.last
101
+ end
102
+
103
+ context "when using a valid id" do
104
+
105
+ context "and domain is successfully verified" do
106
+ before(:each) do
107
+ stub.any_instance_of(AccountDomain).verify { true }
108
+ get :verify, :account_id => @account.id, :domain_id => @domain.id
109
+ end
110
+
111
+ it { response.should redirect_to account_domains_index_path(@account.id) }
112
+
113
+ it { flash.now[:notice].should == I18n.t("iugu.notices.domain_verified") }
114
+
115
+ end
116
+
117
+ context "and domain could not be verified" do
118
+ before(:each) do
119
+ stub.any_instance_of(AccountDomain).verify { false }
120
+ get :verify, :account_id => @account.id, :domain_id => @domain.id
121
+ end
122
+
123
+ it { response.should redirect_to account_domains_index_path(@account.id) }
124
+
125
+ it { flash.now[:notice].should == I18n.t("iugu.notices.domain_not_verified") }
126
+
127
+ end
128
+ end
129
+
130
+ context "when receive an invalid id" do
131
+ before(:each) do
132
+ get :verify, :account_id => @account.id, :domain_id => 1231241241231241231234
133
+ end
134
+
135
+ it { response.should redirect_to account_domains_index_path(@account.id) }
136
+
137
+ it { flash.now[:notice].should == I18n.t("iugu.notices.domain_not_found") }
138
+
139
+ end
140
+ end
141
+
142
+ context "primary" do
143
+ login_as_user
144
+ before(:each) do
145
+ @account = @user.accounts.first
146
+ @account.account_domains << Fabricate(:account_domain){ url "primary.test.net" }
147
+ @domain = @account.account_domains.last
148
+ end
149
+
150
+ context "when receive a valid id" do
151
+ before(:each) do
152
+ post :primary, :account_id => @account.id, :domain_id => @domain.id
153
+ end
154
+
155
+ it { response.should redirect_to account_domains_index_path(@account.id) }
156
+
157
+ it { flash.now[:notice].should == I18n.t("iugu.notices.domain_set_primary") }
158
+
159
+ end
160
+
161
+ context "when receive an invalid id" do
162
+ before(:each) do
163
+ post :primary, :account_id => @account.id, :domain_id => 1231241243141314
164
+ end
165
+
166
+ it { response.should redirect_to account_domains_index_path(@account.id) }
167
+
168
+ it { flash.now[:notice].should == I18n.t("iugu.notices.domain_not_found") }
169
+
170
+ end
171
+
172
+ end
173
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe Iugu::AccountRolesController do
4
+
5
+ context "edit" do
6
+ login_as_user
7
+
8
+ context "when current_user owns the account" do
9
+
10
+ before(:each) do
11
+ @current_account_user = @user.account_users.first
12
+ @current_account_user.set_roles(["owner"])
13
+ get :edit, :id => @current_account_user.account_id, :user_id => @current_account_user.user_id
14
+ end
15
+
16
+ it { response.should render_template "iugu/account_roles/edit" }
17
+ it { response.should be_success }
18
+
19
+ end
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
+ end
36
+
37
+ context "update" do
38
+ login_as_user
39
+ before(:each) do
40
+ @account_id = @user.account_users.first.account_id
41
+ post :update, :id => @account_id, :user_id => @user.id, :roles => []
42
+ end
43
+
44
+ it { response.should redirect_to account_users_index_path(@account_id)}
45
+
46
+ end
47
+
48
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ class StubAccountSettingsController < Iugu::AccountSettingsController
4
+
5
+ def index
6
+ render :text => "true", :status => 200
7
+ end
8
+
9
+ end
10
+
11
+ describe StubAccountSettingsController do
12
+
13
+ def with_stub_routing
14
+ with_routing do |map|
15
+ map.draw do
16
+ match '/stub/account/settings/index' => "stub_account_settings#index"
17
+ end
18
+ yield
19
+ end
20
+ end
21
+
22
+ before(:each) do
23
+ @account = Fabricate(:account)
24
+ end
25
+ login_as_user
26
+
27
+ it 'should render 404' do
28
+ @account.destroy
29
+ with_stub_routing do
30
+ get :index, :account_id => @account.id
31
+ end
32
+ response.should_not be_success
33
+ end
34
+
35
+ it 'should not render 404' do
36
+ with_stub_routing do
37
+ get :index, :account_id => @account.id
38
+ end
39
+ response.should be_success
40
+ end
41
+
42
+ end
@@ -0,0 +1,145 @@
1
+ require 'spec_helper'
2
+
3
+ describe Iugu::AccountUsersController do
4
+ context "index" do
5
+ login_as_user
6
+ before(:each) do
7
+ get :index, :account_id => @user.accounts.first.id
8
+ end
9
+
10
+ it { response.should render_template 'iugu/account_users/index' }
11
+
12
+ end
13
+
14
+ context "view" do
15
+ login_as_user
16
+ before(:each) do
17
+ get :view, :account_id => @user.accounts.first.id, :user_id => @user.id
18
+ end
19
+
20
+ it { response.should render_template 'iugu/account_users/view' }
21
+
22
+ end
23
+
24
+ context "destroy" do
25
+ login_as_user
26
+ before(:each) do
27
+ @account = @user.accounts.first
28
+ end
29
+
30
+ context "when current_user is account owner/admin" do
31
+
32
+ before(:each) do
33
+ @target_user = Fabricate(:user) do
34
+ email 'target@teste.teste'
35
+ end
36
+ @account.account_users << @account_user = AccountUser.create(:user_id => @target_user.id)
37
+ end
38
+
39
+ it 'should raise routing error if account_id is invalid' do
40
+ lambda {
41
+ get :destroy, :account_id => 1892731892371273, :user_id => @target_user.id
42
+ }.should raise_error ActionController::RoutingError
43
+ end
44
+
45
+ it 'should raise routing error if user_id is invalid' do
46
+ lambda {
47
+ get :destroy, :account_id => @account.id, :user_id => 18237198237192837
48
+ }.should raise_error ActionController::RoutingError
49
+ end
50
+
51
+ context "and delete a non owner account" do
52
+ before(:each) do
53
+ @account_user.set_roles ["user"]
54
+ get :destroy, :account_id => @account.id, :user_id => @target_user.id
55
+ end
56
+
57
+ it { response.should redirect_to account_users_index_path(@account.id) }
58
+
59
+ end
60
+
61
+
62
+ context "and dele an owner account" do
63
+ before(:each) do
64
+ @account_user.set_roles ["owner"]
65
+ end
66
+
67
+ it 'should raise routing error' do
68
+ lambda {
69
+ get :destroy, :account_id => @account.id, :user_id => @target_user.id
70
+ }.should raise_error ActionController::RoutingError
71
+ end
72
+
73
+ end
74
+
75
+ context "and try to delete itself from the account" do
76
+ before(:each) do
77
+ @account.account_users.find_by_user_id(@user.id).set_roles ["admin"]
78
+ end
79
+
80
+ it 'should raise routing error' do
81
+ lambda {
82
+ get :destroy, :account_id => @account.id, :user_id => @user.id
83
+ }.should raise_error ActionController::RoutingError
84
+ end
85
+
86
+ end
87
+
88
+ end
89
+
90
+ end
91
+
92
+ context "cancel_destruction" do
93
+ login_as_user
94
+ before(:each) do
95
+ @account = @user.accounts.first
96
+ @target_user = Fabricate(:user) do
97
+ email 'target@test.test'
98
+ end
99
+ @account.account_users << @account_user = AccountUser.create(:user_id => @target_user.id)
100
+ @account_user.set_roles ["user"]
101
+ @account_user.destroy
102
+ end
103
+
104
+ it 'should raise routing error if account_id is invalid' do
105
+ lambda {
106
+ get :cancel_destruction, :account_id => 1892731892371273, :user_id => @target_user.id
107
+ }.should raise_error ActionController::RoutingError
108
+ end
109
+
110
+ it 'should raise routing error if user_id is invalid' do
111
+ lambda {
112
+ get :cancel_destruction, :account_id => @account.id, :user_id => 18237198237192837
113
+ }.should raise_error ActionController::RoutingError
114
+ end
115
+
116
+ context "when current user is owner/admin" do
117
+ before(:each) do
118
+ AccountUser.find_by_user_id_and_account_id(@user.id, @account.id).set_roles ["owner"]
119
+ delete :cancel_destruction, :account_id => @account.id, :user_id => @target_user.id
120
+ end
121
+
122
+ it 'should cancel account_user destruction' do
123
+ @account_user.destroying?.should be_false
124
+ end
125
+
126
+ it { response.should redirect_to account_users_index_path(@account.id) }
127
+
128
+ end
129
+
130
+ context "when current user is not owner/admin" do
131
+ before(:each) do
132
+ @account.account_users << Fabricate(:account_user) { user Fabricate(:user) { email "notowner@account.test" } }
133
+ AccountUser.find_by_user_id_and_account_id(@user.id, @account.id).set_roles ["user"]
134
+ end
135
+
136
+ it 'should raise routing error' do
137
+ lambda {
138
+ delete :cancel_destruction, :account_id => @account.id, :user_id => @target_user.id
139
+ }.should raise_error ActionController::RoutingError
140
+ end
141
+ end
142
+
143
+ end
144
+
145
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ class StubApplicationDomainController < Iugu::ApplicationDomainController
4
+
5
+ def index
6
+ render :text => "true", :status => 200
7
+ end
8
+
9
+ end
10
+
11
+ describe StubApplicationDomainController do
12
+
13
+ def with_stub_routing
14
+ with_routing do |map|
15
+ map.draw do
16
+ match '/stub/application/domain/index' => "stub_application_domain#index"
17
+ end
18
+ yield
19
+ end
20
+ end
21
+
22
+ it 'should be_success' do
23
+ with_stub_routing do
24
+ get :index
25
+ end
26
+ response.should be_success
27
+ end
28
+
29
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe Iugu::InvitationsController do
4
+ context "before filter" do
5
+
6
+ context "when user dont have permissions on account" do
7
+ login_as_user
8
+ before(:each) do
9
+ @account = Fabricate(:account)
10
+ end
11
+
12
+ it 'should raise routing error' do
13
+ lambda {
14
+ get :new, :account_id => @account
15
+ }.should raise_error ActionController::RoutingError
16
+ end
17
+
18
+ end
19
+
20
+ end
21
+
22
+ context "new" do
23
+ login_as_user
24
+ before(:each) do
25
+ @account = @user.accounts.first
26
+ get :new, :account_id => @account.id
27
+ end
28
+
29
+ it { response.should render_template 'iugu/invitations/new' }
30
+
31
+ end
32
+
33
+ context "create" do
34
+ login_as_user
35
+ before(:each) do
36
+ @account = @user.accounts.first
37
+ post :create, :account_id => @account.id, :user_invitation => {:email => "create@controller.teste"}
38
+ end
39
+
40
+ it { response.should redirect_to account_users_index_path(@account.id) }
41
+
42
+ it 'should create an invite' do
43
+ UserInvitation.last.email.should == "create@controller.teste"
44
+ end
45
+
46
+ end
47
+
48
+ context "edit" do
49
+ login_as_user
50
+ before(:each) do
51
+ @user_invitation = Fabricate(:user_invitation)
52
+ @user_invitation.update_attribute(:invited_by, @user.id)
53
+ end
54
+
55
+ context "when token is not valid" do
56
+
57
+ it 'should raise routing error' do
58
+ lambda {
59
+ put :edit, :invitation_token => "9821aaaaabbbbbaaaaaccccc"
60
+ }.should raise_error ActionController::RoutingError
61
+ end
62
+
63
+ end
64
+
65
+ context "when token is valid" do
66
+ before(:each) do
67
+ get :edit, :invitation_token => @user_invitation.id.to_s + @user_invitation.token
68
+ end
69
+
70
+ it { response.should render_template "iugu/invitations/edit" }
71
+
72
+ end
73
+ end
74
+
75
+ context "update" do
76
+ login_as_user
77
+ before(:each) do
78
+ @account = Fabricate(:account)
79
+ @user_invitation = Fabricate(:user_invitation)
80
+ @user_invitation.update_attribute(:account_id, @account.id)
81
+ end
82
+
83
+ context "when token is not valid" do
84
+
85
+ it 'should raise routing error' do
86
+ lambda {
87
+ put :update, :invitation_token => "9821aaaaabbbbbaaaaaccccc"
88
+ }.should raise_error ActionController::RoutingError
89
+ end
90
+
91
+ end
92
+
93
+ context "when token is valid" do
94
+ before(:each) do
95
+ get :update, :invitation_token => @user_invitation.id.to_s + @user_invitation.token
96
+ end
97
+
98
+ it { response.should redirect_to root_path }
99
+
100
+ end
101
+ end
102
+ end