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,77 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Account Domains requests" do
4
+ context "index view" do
5
+ before(:each) do
6
+ visit "/account/auth/facebook"
7
+ @user = User.last
8
+ @account = Account.last
9
+ @account.account_domains << @domain = Fabricate(:account_domain) { url "index.test.net" }
10
+ end
11
+
12
+ context "when domain is primary" do
13
+ before(:each) do
14
+ @domain.update_attribute(:primary, true)
15
+ visit account_domains_index_path(@account.id)
16
+ end
17
+
18
+ it { page.should have_content I18n.t("iugu.primary") }
19
+
20
+ end
21
+
22
+ context "when domain is not primary" do
23
+ before(:each) do
24
+ @domain.update_attribute(:primary, false)
25
+ visit account_domains_index_path(@account.id)
26
+ end
27
+
28
+ it { page.should have_link I18n.t("iugu.set_primary") }
29
+
30
+ end
31
+
32
+ context "when domain is verified" do
33
+ before(:each) do
34
+ @domain.update_attribute(:verified, true)
35
+ visit account_domains_index_path(@account.id)
36
+ end
37
+
38
+ it { page.should have_content I18n.t("iugu.verified") }
39
+
40
+ end
41
+
42
+ context "when domain is not verified" do
43
+ before(:each) do
44
+ @domain.update_attribute(:verified, false)
45
+ visit account_domains_index_path(@account.id)
46
+ end
47
+
48
+ it { page.should have_link I18n.t("iugu.instructions") }
49
+
50
+ end
51
+
52
+ context "when current_user is the owner of the account" do
53
+ before(:each) do
54
+ @account_user = AccountUser.find_by_user_id_and_account_id(@user.id, @account.id)
55
+ @account_user.set_roles ["owner"]
56
+ visit account_domains_index_path(@account.id)
57
+ end
58
+
59
+ it { page.should have_link I18n.t("iugu.remove") }
60
+
61
+ end
62
+
63
+ context "when current_user is not the owner of the account" do
64
+ before(:each) do
65
+ @account.account_users << Fabricate(:account_user) { user Fabricate(:user) { email "notowner@account.test" } }
66
+ @account_user = AccountUser.find_by_user_id_and_account_id(@user.id, @account.id)
67
+ @account_user.set_roles ["user"]
68
+ visit account_domains_index_path(@account.id)
69
+ end
70
+
71
+ it { page.should_not have_link I18n.t("iugu.remove") }
72
+
73
+ end
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Account Roles requests' do
4
+ context "edit view" do
5
+ before(:each) do
6
+ visit '/account/auth/facebook'
7
+ @user = User.last
8
+ @account = @user.accounts.first
9
+ @account_user = @account.account_users.find_by_user_id(@user.id)
10
+ end
11
+
12
+ context "when current_user is account owner" do
13
+ before(:each) do
14
+ @account_user.set_roles [ "owner" ]
15
+ visit account_roles_edit_path(:id => @account.id, :user_id => @user.id)
16
+ end
17
+
18
+ APP_ROLES['roles'].each do |role|
19
+ it { page.should have_content role }
20
+ end
21
+
22
+ end
23
+
24
+ context "when current_user is account admin" do
25
+ before(:each) do
26
+ @account.account_users << Fabricate(:account_user) { user Fabricate(:user) { email "notowner@account.test" } }
27
+ @account_user.set_roles [ "admin" ]
28
+ visit account_roles_edit_path(:id => @account.id, :user_id => @user.id)
29
+ end
30
+
31
+ APP_ROLES['roles'].each do |role|
32
+ if role == APP_ROLES['owner_role'] || role == APP_ROLES['admin_role']
33
+ it { page.should_not have_content role }
34
+ else
35
+ it { page.should have_content role }
36
+ end
37
+ end
38
+
39
+
40
+ end
41
+
42
+
43
+
44
+ end
45
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'accounts settings view' do
4
+ before(:each) do
5
+ visit '/account/auth/facebook'
6
+ visit account_settings_path
7
+ @user = User.last
8
+ @account = Account.last
9
+ end
10
+
11
+ it { page.should have_link I18n.t("iugu.settings") }
12
+
13
+ context "when allow_create_account == false" do
14
+ before(:each) do
15
+ IuguSDK::allow_create_account = false
16
+ end
17
+
18
+ context "and user has only one account" do
19
+ before(:each) do
20
+ @user = User.last
21
+ @user.accounts.destroy_all
22
+ @user.accounts << Fabricate(:account)
23
+ visit account_settings_path
24
+ end
25
+
26
+ it { page.should have_content I18n.t("iugu.account") }
27
+
28
+ end
29
+
30
+ context "and user has more than one account" do
31
+ before(:each) do
32
+ @user = User.last
33
+ @user.accounts.destroy_all
34
+ 2.times { @user.accounts << Fabricate(:account) }
35
+ visit account_settings_path
36
+ end
37
+
38
+ it { page.should have_content I18n.t("iugu.accounts") }
39
+ it { page.should have_link I18n.t("iugu.select") }
40
+
41
+ end
42
+
43
+ end
44
+
45
+ context "Account view" do
46
+ before(:each) do
47
+ @user = User.last
48
+ @user.accounts << @target_account = Fabricate(:account)
49
+ @account_user = AccountUser.last
50
+ end
51
+
52
+ context "when current_user owns the account" do
53
+ before(:each) do
54
+ AccountUser.last.set_roles ["owner"]
55
+ visit account_view_path(@target_account.id)
56
+ end
57
+
58
+ it { page.should have_link I18n.t("iugu.cancel_account") }
59
+
60
+ context "when account is being canceled" do
61
+ context "if delay_account_exclusion == 0" do
62
+ before(:each) do
63
+ IuguSDK::delay_account_exclusion = 0
64
+ click_on I18n.t("iugu.cancel_account")
65
+ visit account_view_path(@target_account.id)
66
+ end
67
+ it { page.should have_content I18n.t("iugu.account_destruction_in") + @target_account.destruction_job.run_at.to_s }
68
+ end
69
+
70
+ context "if delay_account_exclusion > 0" do
71
+ before(:each) do
72
+ IuguSDK::delay_account_exclusion = 1
73
+ click_on I18n.t("iugu.cancel_account")
74
+ visit account_view_path(@target_account.id)
75
+ end
76
+ it { page.should have_link I18n.t("iugu.undo") }
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+
83
+
84
+ context "when current_user do not own the account" do
85
+ before(:each) do
86
+ @target_account.account_users << Fabricate(:account_user) { user Fabricate(:user) { email "notowner@account.test" } }
87
+ @account_user.set_roles ["user"]
88
+ visit account_view_path(@target_account.id)
89
+ end
90
+
91
+ it { page.should_not have_link I18n.t("iugu.cancel_account") }
92
+
93
+ end
94
+
95
+
96
+ end
97
+ end
@@ -0,0 +1,129 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Account Users Requests" do
4
+ before(:each) do
5
+ @user = Fabricate(:user)
6
+ visit '/account/auth/facebook'
7
+ @current_user = User.last
8
+ @account = Account.last
9
+ end
10
+
11
+ context "index" do
12
+
13
+ context "when current_user is account owner" do
14
+
15
+ before(:each) do
16
+ @account.account_users << AccountUser.create(:user_id => @user.id)
17
+ @account.account_users.last.set_roles(["user"])
18
+ @account_user = AccountUser.find_by_account_id_and_user_id(Account.last.id, User.last.id)
19
+ @account_user.set_roles(["owner"])
20
+ visit account_users_index_path(:account_id => User.last.accounts.first.id)
21
+ end
22
+
23
+ it { page.should have_content User.last.name }
24
+ it { page.should have_link I18n.t("iugu.remove") }
25
+ it { page.should have_link I18n.t("iugu.invite") }
26
+ it { page.should have_link I18n.t("iugu.permissions") }
27
+
28
+ end
29
+
30
+ context "when current_user is account admin" do
31
+
32
+ before(:each) do
33
+ @account.account_users << AccountUser.create(:user_id => @user.id)
34
+ @account.account_users.last.set_roles(["user"])
35
+ @account_user = AccountUser.find_by_account_id_and_user_id(Account.last.id, User.last.id)
36
+ @account_user.set_roles(["admin"])
37
+ visit account_users_index_path(:account_id => User.last.accounts.first.id)
38
+ end
39
+
40
+ it { page.should have_content User.last.name }
41
+ it { page.should have_link I18n.t("iugu.remove") }
42
+ it { page.should have_link I18n.t("iugu.invite") }
43
+ it { page.should have_link I18n.t("iugu.permissions") }
44
+
45
+ end
46
+
47
+ context "when current_user is not owner nor admin" do
48
+
49
+ before(:each) do
50
+ @account.account_users << Fabricate(:account_user) { user Fabricate(:user) { email "notowner@account.test" } }
51
+ @account.account_users << AccountUser.create(:user_id => @user.id)
52
+ @account.account_users.last.set_roles(["user"])
53
+ @account_user = AccountUser.find_by_account_id_and_user_id(@account.id, @current_user.id)
54
+ @account_user.set_roles(["user"])
55
+ visit account_users_index_path(:account_id => @current_user.accounts.first.id)
56
+ end
57
+
58
+ it { page.should have_content User.last.name }
59
+ it { page.should_not have_link I18n.t("iugu.remove") }
60
+ it { page.should have_link I18n.t("iugu.invite") }
61
+ it { page.should_not have_link I18n.t("iugu.permissions") }
62
+
63
+ end
64
+
65
+ context "when current_user and account_user are owners" do
66
+ before(:each) do
67
+ @account.account_users << AccountUser.create(:user_id => @user.id)
68
+ @account.account_users.last.set_roles(["owner"])
69
+ @account_user = AccountUser.find_by_account_id_and_user_id(Account.last.id, @current_user.id)
70
+ @account_user.set_roles(["owner"])
71
+ visit account_users_index_path(:account_id => @current_user.accounts.first.id)
72
+ end
73
+
74
+ it { page.should have_content User.last.name }
75
+ it { page.should_not have_link I18n.t("iugu.remove") }
76
+ it { page.should have_link I18n.t("iugu.invite") }
77
+ it { page.should have_link I18n.t("iugu.permissions") }
78
+
79
+ end
80
+
81
+ context "when current_user is the only user of the account" do
82
+ before(:each) do
83
+ @account_user = AccountUser.find_by_account_id_and_user_id(Account.last.id, @current_user.id)
84
+ @account_user.set_roles(["owner"])
85
+ visit account_users_index_path(:account_id => @current_user.accounts.first.id)
86
+ end
87
+
88
+ it { page.should have_content User.last.name }
89
+ it { page.should_not have_link I18n.t("iugu.remove") }
90
+ it { page.should have_link I18n.t("iugu.invite") }
91
+ it { page.should have_link I18n.t("iugu.permissions") }
92
+
93
+ end
94
+
95
+ end
96
+
97
+ context "destroy" do
98
+ before(:each) do
99
+ @account.account_users << AccountUser.create(:user_id => @user.id)
100
+ @account.account_users.last.set_roles(["user"])
101
+ @account_user = AccountUser.find_by_account_id_and_user_id(Account.last.id, User.last.id)
102
+ @account_user.set_roles(["owner"])
103
+ visit account_users_index_path(:account_id => User.last.accounts.first.id)
104
+ end
105
+
106
+ context "when delay_account_user_exclusion == 0" do
107
+ before(:each) do
108
+ IuguSDK::delay_account_user_exclusion = 0
109
+ click_on I18n.t("iugu.remove")
110
+ end
111
+
112
+ it { page.should have_content I18n.t("iugu.removing") }
113
+ it { page.should_not have_link I18n.t("iugu.undo") }
114
+
115
+ end
116
+
117
+ context "when delay_account_user_exclusion > 0" do
118
+ before(:each) do
119
+ IuguSDK::delay_account_user_exclusion = 1
120
+ click_on I18n.t("iugu.remove")
121
+ end
122
+
123
+ it { page.should_not have_content I18n.t("iugu.removing") }
124
+ it { page.should have_link I18n.t("iugu.undo") }
125
+
126
+ end
127
+
128
+ end
129
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'omniauth requests' do
4
+ context "provider not found" do
5
+ before(:each) do
6
+ visit '/account/auth/orkut'
7
+ end
8
+
9
+ it { page.should have_content "Not found" }
10
+
11
+ end
12
+
13
+ context "facebook" do
14
+ context 'not signed in' do
15
+ before(:each) do
16
+ visit '/account/auth/facebook'
17
+ end
18
+
19
+ it { page.should have_content "signed in" }
20
+ end
21
+
22
+ context "already signed in" do
23
+ before(:each) do
24
+ visit new_user_session_path
25
+ Fabricate(:user, :email => 'test@test.test', :password => 'testing', :password_confirmation => 'testing')
26
+ fill_in 'user_email', :with => "test@test.test"
27
+ fill_in 'user_password', :with => "testing"
28
+ click_on 'Sign in'
29
+ visit '/account/auth/facebook'
30
+ visit '/settings/profile'
31
+ end
32
+
33
+ it { page.should have_content "UID" }
34
+
35
+ end
36
+
37
+ context "with email already used" do
38
+ before(:each) do
39
+ email = OmniAuth.config.mock_auth[:facebook]["extra"]["raw_info"]["email"]
40
+ Fabricate(:user, :email => email)
41
+ visit '/account/auth/facebook'
42
+ end
43
+
44
+ it { page.should have_content I18n.t('errors.messages.email_already_in_use') }
45
+
46
+ end
47
+
48
+ end
49
+
50
+ context "twitter" do
51
+
52
+ context "not signed in" do
53
+
54
+ before(:each) do
55
+ visit '/account/auth/twitter'
56
+ end
57
+
58
+ it { page.should have_content "signed in" }
59
+
60
+ end
61
+
62
+ context "already signed in" do
63
+
64
+ before(:each) do
65
+ visit new_user_session_path
66
+ Fabricate(:user, :email => 'test@test.test', :password => 'testing', :password_confirmation => 'testing')
67
+ fill_in 'user_email', :with => "test@test.test"
68
+ fill_in 'user_password', :with => "testing"
69
+ click_on 'Sign in'
70
+ visit '/account/auth/twitter'
71
+ visit '/settings/profile'
72
+ end
73
+
74
+ it { page.should have_content "UID" }
75
+
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Settings requests" do
4
+ context "settings layout" do
5
+ before(:each) do
6
+ visit '/account/auth/facebook'
7
+ end
8
+
9
+ context "when allow_create_accounts == false" do
10
+ before(:each) do
11
+ IuguSDK::allow_create_account = false
12
+ end
13
+
14
+ context "when user has only 1 account" do
15
+ before(:each) do
16
+ @user = User.last
17
+ @user.accounts.destroy_all
18
+ @user.accounts << Fabricate(:account)
19
+ visit settings_path
20
+ end
21
+
22
+ it { page.should have_link I18n.t("iugu.account") }
23
+
24
+ end
25
+
26
+ context "when user has more than 1 account" do
27
+ before(:each) do
28
+ @user = User.last
29
+ @user.accounts.destroy_all
30
+ 2.times { @user.accounts << Fabricate(:account) }
31
+ visit settings_path
32
+ end
33
+
34
+ it { page.should have_link I18n.t("iugu.accounts") }
35
+
36
+ end
37
+ end
38
+
39
+
40
+ context "when allow_create_accounts == true" do
41
+ before(:each) do
42
+ IuguSDK::allow_create_account = true
43
+ visit settings_path
44
+ end
45
+
46
+ it { page.should have_link I18n.t("iugu.accounts") }
47
+
48
+ end
49
+
50
+
51
+
52
+ end
53
+ end