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,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ <p>We've been notified about this issue and we'll take a look at it shortly.</p>
24
+ </div>
25
+ </body>
26
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
File without changes
@@ -0,0 +1,4 @@
1
+ Fabricator(:account_domain) do
2
+ account_id 1
3
+ url "www.testing.net"
4
+ end
@@ -0,0 +1,4 @@
1
+ Fabricator(:account) do
2
+ name "jabanilson"
3
+ subscription_id 1
4
+ end
@@ -0,0 +1,3 @@
1
+ Fabricator(:account_role) do
2
+ name "guest"
3
+ end
@@ -0,0 +1,4 @@
1
+ Fabricator(:account_user) do
2
+ account
3
+ user
4
+ end
@@ -0,0 +1,10 @@
1
+ Fabricator(:social_account) do
2
+ user!
3
+ provider "twitter"
4
+ social_id "123123123"
5
+ end
6
+
7
+ Fabricator(:social_account_without_user, :class_name => :social_account) do
8
+ provider "twitter"
9
+ social_id "123123123"
10
+ end
@@ -0,0 +1,10 @@
1
+ Fabricator(:user) do
2
+ email "teste@teste.com"
3
+ password "123456"
4
+ confirmed_at Time.now
5
+ end
6
+
7
+ Fabricator(:user_without_email, :class_name => :user) do
8
+ password "123456"
9
+ confirmed_at Time.now
10
+ end
@@ -0,0 +1,4 @@
1
+ Fabricator(:user_invitation) do
2
+ email 'teste@teste.teste'
3
+ account_id 100
4
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe IuguMailer do
4
+ before(:each) do
5
+ @user_invitation = Fabricate(:user_invitation)
6
+ end
7
+
8
+ it 'should not raise an error' do
9
+ lambda {IuguMailer.invitation(@user_invitation)}.should_not raise_error
10
+ end
11
+
12
+ context "rendered without error" do
13
+ before(:each) do
14
+ @mailer = IuguMailer.invitation(@user_invitation)
15
+ end
16
+
17
+ it 'should have a link to accept invite' do
18
+ @mailer.body.should have_link edit_invite_path(:invitation_token => @user_invitation.id.to_s + @user_invitation.token)
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,111 @@
1
+ require 'spec_helper'
2
+ describe AccountDomain do
3
+
4
+ before(:each) do
5
+ Fabricate(:account_domain)
6
+ end
7
+
8
+ it { should belong_to :account }
9
+ it { should validate_presence_of(:url) }
10
+ it { should validate_presence_of(:account_id) }
11
+
12
+ it 'should accept url with correct pattern' do
13
+ @account_domain = Fabricate.build(:account_domain) do
14
+ url 'www.t3st.net'
15
+ end.should be_valid
16
+ end
17
+
18
+ it 'should not accept url with incorrect pattern' do
19
+ Fabricate.build(:account_domain) do
20
+ url 'http://www.t3st.net'
21
+ end.should_not be_valid
22
+ end
23
+
24
+ it 'should not accept url in the blacklist' do
25
+ IuguSDK::custom_domain_invalid_hosts = ['invalid.domain.test']
26
+ Fabricate.build(:account_domain) do
27
+ url 'invalid.domain.test'
28
+ end.should_not be_valid
29
+ end
30
+
31
+ context "normalize_host" do
32
+ it 'should return normalized host' do
33
+ @account_domain = Fabricate(:account_domain) do
34
+ url "www.normal.host"
35
+ end
36
+ @account_domain.normalize_host.should == "normal.host"
37
+ end
38
+ end
39
+
40
+ context "calculate_token" do
41
+ it 'should return url token' do
42
+ @account_domain = Fabricate(:account_domain) do
43
+ url "www.normal.host"
44
+ end
45
+ @account_domain.calculate_token.class.should == String
46
+ end
47
+ end
48
+
49
+ context "verify" do
50
+ it 'should return true for valid url' do
51
+ @account_domain = Fabricate(:account_domain) do
52
+ url "www.test.net"
53
+ end
54
+ @account_domain.verify
55
+ @account_domain.verified.should be_true
56
+ end
57
+
58
+ it 'should return false for invalid url' do
59
+ @account_domain = Fabricate(:account_domain) do
60
+ url "invalid.url.false"
61
+ end
62
+ @account_domain.verify
63
+ @account_domain.verified.should be_false
64
+ end
65
+
66
+ it 'should unverify other domains with equal url' do
67
+ @account_domain1 = Fabricate(:account_domain) do
68
+ url "www.test.net"
69
+ end
70
+ @account_domain1.update_attribute(:verified, true)
71
+ @account_domain2 = Fabricate(:account_domain) do
72
+ url "www.test.net"
73
+ end
74
+
75
+ @account_domain2.verify
76
+
77
+ @account_domain1.reload
78
+ @account_domain1.verified.should be_false
79
+ end
80
+
81
+ end
82
+
83
+ context "set_primary" do
84
+ before(:each) do
85
+ @account = Fabricate(:account)
86
+ @account.account_domains << @domain1 = Fabricate(:account_domain) do
87
+ url "www.url1.net"
88
+ verified true
89
+ primary false
90
+ end
91
+ @account.account_domains << @domain2 = Fabricate(:account_domain) do
92
+ url "www.url2.net"
93
+ verified true
94
+ primary true
95
+ end
96
+ end
97
+
98
+ it 'should make domain primary' do
99
+ @domain1.set_primary
100
+ @domain1.primary.should be_true
101
+ end
102
+
103
+ it 'should make other account domains not primary' do
104
+ @domain1.set_primary
105
+ @domain2.reload
106
+ @domain2.primary.should be_false
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe AccountRole do
4
+ subject {
5
+ user = Fabricate( :user )
6
+ user.account_users.first.roles.destroy_all
7
+ @account_user = user.account_users.first
8
+ Fabricate( :account_role, :account_user => @account_user )
9
+ }
10
+
11
+ it { should belong_to :account_user }
12
+ it { should validate_uniqueness_of(:name).scoped_to(:account_user_id) }
13
+ it { should validate_presence_of(:account_user) }
14
+
15
+ it 'should only accept configured roles' do
16
+ subject.name = "not a role"
17
+ subject.should_not be_valid
18
+ end
19
+
20
+ it 'roles class method should return available roles' do
21
+ AccountRole.roles.should == APP_ROLES['roles']
22
+ end
23
+
24
+ end
@@ -0,0 +1,155 @@
1
+ require 'spec_helper'
2
+
3
+ describe Account do
4
+ before(:each) do
5
+ Fabricate(:account){ subdomain "unico" }
6
+ end
7
+
8
+ it { should have_many(:account_domains) }
9
+ it { should have_many(:account_users) }
10
+ it { should have_many(:users).through(:account_users) }
11
+ it { should validate_uniqueness_of(:subdomain) }
12
+
13
+ it "should return true for a valid user of account" do
14
+ @user = Fabricate(:user, :email => "me@me.com")
15
+ @account = Fabricate(:account)
16
+ @account.account_users << Fabricate(:account_user, :user => @user)
17
+ @account.valid_user_for_account?( @user ).should be_true
18
+ end
19
+
20
+ it 'should no accept subdomains in blacklist' do
21
+ IuguSDK::custom_domain_invalid_prefixes = [ 'subdominio' ]
22
+ @account = Fabricate.build(:account) { subdomain "subdominio" }.should_not be_valid
23
+ end
24
+
25
+ context "destruction_job method" do
26
+ before(:each) do
27
+ @account = Fabricate(:account)
28
+ end
29
+
30
+ it 'should return a job' do
31
+ @account.destroy
32
+ @account.destruction_job.class.should == Delayed::Backend::ActiveRecord::Job
33
+ end
34
+
35
+ it 'should return null if account has no destruction job' do
36
+ @account.destruction_job.should be_nil
37
+ end
38
+
39
+ end
40
+
41
+ context "destrying? method" do
42
+ before(:each) do
43
+ @account = Fabricate(:account)
44
+ end
45
+
46
+ it 'should return true if account has a destruction job' do
47
+ @account.destroy
48
+ @account.destroying?.should be_true
49
+ end
50
+
51
+ it 'should return false if account doesnt have a destruction job' do
52
+ @account.destroying?.should be_false
53
+ end
54
+ end
55
+
56
+ context "cancel_destruction" do
57
+ before(:each) do
58
+ @account = Fabricate(:account)
59
+ end
60
+
61
+ it 'should cancel account destruction' do
62
+ @account.destroy
63
+ @account.cancel_destruction
64
+ @account.destroying?.should be_false
65
+ end
66
+
67
+ it 'should return a job' do
68
+ @account.destroy
69
+ @account.cancel_destruction.class.should == Delayed::Backend::ActiveRecord::Job
70
+ end
71
+
72
+ it 'should return nil if doesnt have a destruction job' do
73
+ @account.cancel_destruction.should be_nil
74
+ end
75
+
76
+ it 'should return nil if destruction job is already locked' do
77
+ @account.destroy
78
+ @job = @account.destruction_job
79
+ @job.locked_at = Time.now
80
+ @job.save
81
+ @account.cancel_destruction.should be_nil
82
+ end
83
+
84
+ end
85
+
86
+ context "is? method" do
87
+ before(:each) do
88
+ @user = Fabricate(:user)
89
+ @account = @user.accounts.first
90
+ @account_user = @account.account_users.find_by_user_id(@user.id)
91
+ @account_user.roles.destroy_all
92
+ @account_user.roles << AccountRole.create(:name => "user")
93
+ end
94
+
95
+ it 'should return true if user has the role for the account' do
96
+ @account.is?(:user, @user).should be_true
97
+ end
98
+
99
+ it 'should return if user hasnt the role for the account' do
100
+ @account.is?(:admin, @user).should be_false
101
+ end
102
+
103
+ end
104
+
105
+ context "name" do
106
+ before(:each) do
107
+ @account = Fabricate(:account)
108
+ end
109
+
110
+ it 'should return account name' do
111
+ @account.name = "Named"
112
+ @account.save
113
+ @account.name.should == "Named"
114
+ end
115
+
116
+ it 'should return Account #ID if account name == nil' do
117
+ @account.name = nil
118
+ @account.save
119
+ @account.name.should == "#{I18n.t("iugu.account")} ##{@account.id}"
120
+ end
121
+
122
+ it 'should return Account #ID if account name is blank' do
123
+ @account.name = ""
124
+ @account.save
125
+ @account.name.should == "#{I18n.t("iugu.account")} ##{@account.id}"
126
+ end
127
+
128
+ end
129
+
130
+ context "get_from_domain" do
131
+ before(:each) do
132
+ @account = Fabricate(:account) do
133
+ subdomain "subdomainfind"
134
+ end
135
+ @account.account_domains << Fabricate(:account_domain) do
136
+ url "getfromdomain.account.test"
137
+ verified true
138
+ end
139
+ end
140
+
141
+ it 'should return the account which owns the domain' do
142
+ Account.get_from_domain("getfromdomain.account.test").should == @account
143
+ end
144
+
145
+ it 'should return the account which owns the subdomain' do
146
+ Account.get_from_domain("subdomainfind.iugusdk.dev").should == @account
147
+ end
148
+
149
+ it 'should return nil ' do
150
+ Account.get_from_domain("notused.domain.test").should be_nil
151
+ end
152
+ end
153
+
154
+
155
+ end