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.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +39 -0
- data/app/assets/images/application_logo.png +0 -0
- data/app/assets/javascripts/settings.js +10 -0
- data/app/assets/javascripts/settings_code.js.coffee.erb +0 -0
- data/app/assets/stylesheets/settings.sass +120 -0
- data/app/controllers/iugu/account_controller.rb +63 -0
- data/app/controllers/iugu/account_domains_controller.rb +64 -0
- data/app/controllers/iugu/account_roles_controller.rb +20 -0
- data/app/controllers/iugu/account_settings_controller.rb +17 -0
- data/app/controllers/iugu/account_users_controller.rb +43 -0
- data/app/controllers/iugu/application_domain_controller.rb +11 -0
- data/app/controllers/iugu/confirmations_controller.rb +2 -0
- data/app/controllers/iugu/invitations_controller.rb +49 -0
- data/app/controllers/iugu/omniauth_callbacks_controller.rb +23 -0
- data/app/controllers/iugu/passwords_controller.rb +2 -0
- data/app/controllers/iugu/profile_controller.rb +44 -0
- data/app/controllers/iugu/registrations_controller.rb +3 -0
- data/app/controllers/iugu/sessions_controller.rb +2 -0
- data/app/controllers/iugu/settings_controller.rb +11 -0
- data/app/controllers/iugu/unlocks_controller.rb +2 -0
- data/app/mailers/iugu_mailer.rb +16 -0
- data/app/models/account.rb +53 -0
- data/app/models/account_domain.rb +69 -0
- data/app/models/account_role.rb +24 -0
- data/app/models/account_user.rb +55 -0
- data/app/models/available_language.rb +10 -0
- data/app/models/social_account.rb +14 -0
- data/app/models/user.rb +107 -0
- data/app/models/user_invitation.rb +39 -0
- data/app/validators/email_validator.rb +17 -0
- data/app/views/iugu-old/account_settings.html.haml +17 -0
- data/app/views/iugu-old/login.html.haml +28 -0
- data/app/views/iugu-old/mails/confirmation_instructions.html.erb +5 -0
- data/app/views/iugu-old/mails/reset_password_instructions.html.erb +8 -0
- data/app/views/iugu-old/mails/unlock_instructions.html.erb +7 -0
- data/app/views/iugu-old/profile_settings.html.haml +76 -0
- data/app/views/iugu-old/signup.html.haml +36 -0
- data/app/views/iugu/account_domains/index.html.haml +33 -0
- data/app/views/iugu/account_domains/instructions.html.haml +0 -0
- data/app/views/iugu/account_roles/edit.html.haml +17 -0
- data/app/views/iugu/account_roles/update.html.haml +0 -0
- data/app/views/iugu/account_users/index.html.haml +23 -0
- data/app/views/iugu/account_users/view.html.haml +0 -0
- data/app/views/iugu/confirmations/new.html.haml +8 -0
- data/app/views/iugu/invitations/edit.html.haml +8 -0
- data/app/views/iugu/invitations/new.html.haml +13 -0
- data/app/views/iugu/mailer/confirmation_instructions.html.haml +4 -0
- data/app/views/iugu/mailer/invitation.html.haml +1 -0
- data/app/views/iugu/mailer/reset_password_instructions.html.haml +4 -0
- data/app/views/iugu/mailer/unlock_instructions.html.haml +5 -0
- data/app/views/iugu/passwords/edit.html.haml +11 -0
- data/app/views/iugu/passwords/new.html.haml +8 -0
- data/app/views/iugu/registrations/edit.html.haml +15 -0
- data/app/views/iugu/registrations/new.html.haml +11 -0
- data/app/views/iugu/sessions/new.html.haml +9 -0
- data/app/views/iugu/settings/account.html.haml +48 -0
- data/app/views/iugu/settings/accounts.html.haml +33 -0
- data/app/views/iugu/settings/profile.html.haml +96 -0
- data/app/views/iugu/shared/_links.haml +19 -0
- data/app/views/iugu/unlocks/new.html.haml +8 -0
- data/app/views/layouts/settings.html.haml +46 -0
- data/config/initializers/account_roles.rb +5 -0
- data/config/initializers/devise.rb +242 -0
- data/config/initializers/social_accounts.rb +16 -0
- data/config/locales/devise.en.yml +57 -0
- data/config/locales/devise.pt-BR.yml +55 -0
- data/config/locales/iugu.en.yml +73 -0
- data/config/locales/iugu.pt-BR.yml +73 -0
- data/config/routes.rb +77 -0
- data/db/migrate/20120528164634_create_account.rb +11 -0
- data/db/migrate/20120529134109_add_devise_to_users.rb +53 -0
- data/db/migrate/20120529162901_add_birthdate_and_name_to_user.rb +12 -0
- data/db/migrate/20120529174755_add_name_and_subscription_id_and_user_id_to_account.rb +13 -0
- data/db/migrate/20120529180814_create_account_users.rb +12 -0
- data/db/migrate/20120530114709_remove_user_id_from_accounts.rb +9 -0
- data/db/migrate/20120531171438_create_account_roles.rb +12 -0
- data/db/migrate/20120604131034_add_locale_to_user.rb +9 -0
- data/db/migrate/20120605142527_create_social_account.rb +15 -0
- data/db/migrate/20120612141130_set_locale.rb +6 -0
- data/db/migrate/20120613173114_remove_unique_from_user_email.rb +11 -0
- data/db/migrate/20120615180728_create_delayed_jobs.rb +22 -0
- data/db/migrate/20120629154429_create_user_invitations.rb +14 -0
- data/db/migrate/20120629195345_add_token_to_user_invitations.rb +8 -0
- data/db/migrate/20120705202827_add_roles_to_user_invitations.rb +8 -0
- data/db/migrate/20120716145846_create_account_domain.rb +14 -0
- data/db/migrate/20120719162426_add_subdomain_to_account.rb +9 -0
- data/lib/iugusdk.rb +73 -0
- data/lib/iugusdk/controllers/helpers.rb +45 -0
- data/lib/iugusdk/engine.rb +13 -0
- data/lib/iugusdk/locale_filter.rb +12 -0
- data/lib/iugusdk/root_tenancy_url.rb +22 -0
- data/lib/iugusdk/valid_tenancy_urls.rb +27 -0
- data/lib/iugusdk/version.rb +3 -0
- data/lib/tasks/iugusdk_tasks.rake +4 -0
- data/spec/controller_macros.rb +41 -0
- data/spec/controllers/account_controller_spec.rb +155 -0
- data/spec/controllers/account_domains_controller_spec.rb +173 -0
- data/spec/controllers/account_roles_controller_spec.rb +48 -0
- data/spec/controllers/account_settings_controller_spec.rb +42 -0
- data/spec/controllers/account_users_controller_spec.rb +145 -0
- data/spec/controllers/application_domain_controller_spec.rb +29 -0
- data/spec/controllers/invitations_controller_spec.rb +102 -0
- data/spec/controllers/profile_controller_spec.rb +125 -0
- data/spec/controllers/settings_controller_spec.rb +14 -0
- data/spec/dummy/Rakefile +7 -0
- data/spec/dummy/app/assets/javascripts/application.js +9 -0
- data/spec/dummy/app/assets/stylesheets/application.css +7 -0
- data/spec/dummy/app/assets/stylesheets/default.sass +111 -0
- data/spec/dummy/app/controllers/application_controller.rb +3 -0
- data/spec/dummy/app/controllers/dashboard_controller.rb +8 -0
- data/spec/dummy/app/controllers/my_dummy_controller.rb +9 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/dashboard/index.html.haml +5 -0
- data/spec/dummy/app/views/dashboard/splash.html.haml +10 -0
- data/spec/dummy/app/views/layouts/application.html.erb +29 -0
- data/spec/dummy/app/views/layouts/dummy.html.erb +22 -0
- data/spec/dummy/app/views/my_dummy/index.html.haml +5 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/account_roles.yml +3 -0
- data/spec/dummy/config/application.rb +66 -0
- data/spec/dummy/config/boot.rb +10 -0
- data/spec/dummy/config/database.yml +37 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +60 -0
- data/spec/dummy/config/environments/test.rb +40 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/inflections.rb +10 -0
- data/spec/dummy/config/initializers/iugusdk.rb +4 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +7 -0
- data/spec/dummy/config/initializers/session_store.rb +8 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +5 -0
- data/spec/dummy/config/routes.rb +69 -0
- data/spec/dummy/config/social_accounts.yml +6 -0
- data/spec/dummy/db/schema.rb +95 -0
- data/spec/dummy/public/404.html +26 -0
- data/spec/dummy/public/422.html +26 -0
- data/spec/dummy/public/500.html +26 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/script/rails +6 -0
- data/spec/dummy/tmp/cache/sass/1f198e4a81e57d6c86c6fff1f0e13592b233ebc2/prettify.cssc +0 -0
- data/spec/dummy/tmp/cache/sass/40796b6ca2cf9112b889007328d8a4c5fdc634d8/_css3.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/40796b6ca2cf9112b889007328d8a4c5fdc634d8/_support.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/components.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/iugu-ux.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/mixins.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/reset.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/typography.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/utilities.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/589e829967f8e21bd017e2d6a46ea53360f10fe0/variables.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_appearance.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-clip.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-origin.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_background-size.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_border-radius.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box-shadow.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box-sizing.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_box.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_columns.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_font-face.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_images.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_inline-block.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_opacity.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_shared.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_text-shadow.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_transform.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/7694fbc0853be2496915aae45b37e2d934ffc111/_transition.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/9da4e62a062dae83baa33f29455be2ba30cf5dce/_sprites.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/db2a23483187bf5625185da2d6f47de2a6de4989/_base.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/db2a23483187bf5625185da2d6f47de2a6de4989/_sprite-img.scssc +0 -0
- data/spec/dummy/tmp/cache/sass/e5be18dde92936a4632e65289dad5788ed73dd60/base_settings.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/e5be18dde92936a4632e65289dad5788ed73dd60/settings.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/application.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/base_settings.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/e764476e9a85279ad82622591ce49983ed21c149/default.sassc +0 -0
- data/spec/dummy/tmp/cache/sass/eab9c0816f626278a6731ce2928de6fdbe99322b/_hacks.scssc +0 -0
- data/spec/dummy/tmp/restart.txt +0 -0
- data/spec/fabricators/account_domain_fabricator.rb +4 -0
- data/spec/fabricators/account_fabricator.rb +4 -0
- data/spec/fabricators/account_role_fabricator.rb +3 -0
- data/spec/fabricators/account_user_fabricator.rb +4 -0
- data/spec/fabricators/social_account_fabricator.rb +10 -0
- data/spec/fabricators/user_fabricator.rb +10 -0
- data/spec/fabricators/user_invitation_fabricator.rb +4 -0
- data/spec/mailers/iugu_mailer_spec.rb +22 -0
- data/spec/models/account_domain_spec.rb +111 -0
- data/spec/models/account_role_spec.rb +24 -0
- data/spec/models/account_spec.rb +155 -0
- data/spec/models/account_user_spec.rb +158 -0
- data/spec/models/social_account_spec.rb +36 -0
- data/spec/models/user_invitation_spec.rb +92 -0
- data/spec/models/user_spec.rb +187 -0
- data/spec/requests/account_domain_spec.rb +77 -0
- data/spec/requests/account_roles_spec.rb +45 -0
- data/spec/requests/account_spec.rb +97 -0
- data/spec/requests/account_users_spec.rb +129 -0
- data/spec/requests/omniauth_spec.rb +79 -0
- data/spec/requests/settings_spec.rb +53 -0
- data/spec/requests/user_invitation_spec.rb +40 -0
- data/spec/requests/user_spec.rb +34 -0
- data/spec/spec_helper.rb +116 -0
- data/spec/validators/email_validator_spec.rb +21 -0
- metadata +729 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe AccountUser do
|
|
4
|
+
before(:each) { @account_user = Fabricate(:account_user) }
|
|
5
|
+
|
|
6
|
+
it { should have_many :roles }
|
|
7
|
+
|
|
8
|
+
context "is? method" do
|
|
9
|
+
before(:each) do
|
|
10
|
+
@account_user.roles.destroy_all()
|
|
11
|
+
@account_user.roles << Fabricate( :account_role, :name => "user", :account_user => @account_user )
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it 'should return true when have the role' do
|
|
15
|
+
@account_user.is?("user").should be_true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'should return false when dont have the role' do
|
|
19
|
+
@account_user.is?("admin").should be_false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it 'should return true when have the role but searched with :param' do
|
|
23
|
+
@account_user.is?(:user).should be_true
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "is? method with different roles" do
|
|
28
|
+
|
|
29
|
+
before(:each) do
|
|
30
|
+
@account = @account_user.account
|
|
31
|
+
@account.account_users << Fabricate(:account_user) { user Fabricate(:user) { email "notowner@account.test" } }
|
|
32
|
+
@account_user.roles.destroy_all()
|
|
33
|
+
puts @account_user.roles
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "when we have configured alias for roles" do
|
|
37
|
+
# Stub CONSTANTS
|
|
38
|
+
before(:all) do
|
|
39
|
+
OLD_ROLES = APP_ROLES
|
|
40
|
+
silence_warnings{ APP_ROLES = {"roles"=>["my_owner", "my_user"], "owner_role"=>"my_owner", "admin_role" => "my_user" } }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "should find by the role when trying to check owner" do
|
|
44
|
+
@account_user.set_roles ["my_owner"]
|
|
45
|
+
@account_user.is?("owner").should be_true
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "should find by the role when trying to check admin" do
|
|
49
|
+
@account_user.set_roles ["my_user"]
|
|
50
|
+
@account_user.is?( "admin" ).should be_true
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
after(:all) do
|
|
54
|
+
silence_warnings{ APP_ROLES = OLD_ROLES }
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
context "set_roles method" do
|
|
61
|
+
before(:all) do
|
|
62
|
+
silence_warnings{ APP_ROLES = {"roles"=>["my_owner", "my_user", "my_guest"], "owner_role"=>"my_owner", "admin_role" => "my_user" } }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
before(:each) do
|
|
66
|
+
@account_user.roles.destroy_all
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'should update roles' do
|
|
70
|
+
@account_user.set_roles ["my_guest"]
|
|
71
|
+
@account_user.is?("my_guest").should be_true
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it 'should return true' do
|
|
75
|
+
@account_user.set_roles(["my_user"]).should be_true
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
it 'should return false if receive an invalid role' do
|
|
79
|
+
@account_user.set_roles(["invalid_role"]).should be_false
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
it 'should return true if receive nil' do
|
|
83
|
+
@account_user.set_roles(nil).should be_true
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
it 'should destroy all roles if receive nil' do
|
|
87
|
+
@account_user.set_roles(nil)
|
|
88
|
+
@account_user.roles.empty?.should be_true
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
after(:all) do
|
|
92
|
+
silence_warnings{ APP_ROLES = OLD_ROLES }
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
context "destruction_job method" do
|
|
98
|
+
|
|
99
|
+
it 'should return a job' do
|
|
100
|
+
@account_user.destroy
|
|
101
|
+
@account_user.destruction_job.class.should == Delayed::Backend::ActiveRecord::Job
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
it 'should return null if account has no destruction job' do
|
|
105
|
+
@account_user.destruction_job.should be_nil
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
context "destrying? method" do
|
|
111
|
+
before(:each) do
|
|
112
|
+
@account = Fabricate(:account)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'should return true if account has a destruction job' do
|
|
116
|
+
@account_user.destroy
|
|
117
|
+
@account_user.destroying?.should be_true
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
it 'should return false if account doesnt have a destruction job' do
|
|
121
|
+
@account_user.destroying?.should be_false
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
context "cancel_destruction" do
|
|
126
|
+
before(:each) do
|
|
127
|
+
@account = Fabricate(:account)
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
it 'should cancel account destruction' do
|
|
131
|
+
@account_user.destroy
|
|
132
|
+
@account_user.cancel_destruction
|
|
133
|
+
@account_user.destroying?.should be_false
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
it 'should return a job' do
|
|
137
|
+
@account_user.destroy
|
|
138
|
+
@account_user.cancel_destruction.class.should == Delayed::Backend::ActiveRecord::Job
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'should return nil if doesnt have a destruction job' do
|
|
142
|
+
@account_user.cancel_destruction.should be_nil
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
it 'should return nil if destruction job is already locked' do
|
|
146
|
+
@account_user.destroy
|
|
147
|
+
@job = @account_user.destruction_job
|
|
148
|
+
@job.locked_at = Time.now
|
|
149
|
+
@job.save
|
|
150
|
+
@account_user.cancel_destruction.should be_nil
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe SocialAccount do
|
|
4
|
+
it { should belong_to :user }
|
|
5
|
+
|
|
6
|
+
it 'cant be unlinked if the user has no email and its the last social' do
|
|
7
|
+
@user = Fabricate.build(:user_without_email)
|
|
8
|
+
@user.password = "secret_password"
|
|
9
|
+
@user.password_confirmation = "secret_password"
|
|
10
|
+
@user.skip_confirmation!
|
|
11
|
+
@user.save(:validate => false)
|
|
12
|
+
@user.social_accounts << Fabricate(:social_account_without_user)
|
|
13
|
+
User.find(@user.id).social_accounts.first.unlink.should be_false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it 'cant be unlinked if the user has no password and its the last social' do
|
|
17
|
+
@social_account = Fabricate(:social_account)
|
|
18
|
+
@user = @social_account.user
|
|
19
|
+
@user.email = "testing@email.test"
|
|
20
|
+
@user.password = ""
|
|
21
|
+
@user.password_confirmation = ""
|
|
22
|
+
@user.encrypted_password = ""
|
|
23
|
+
@user.save(:validate => false)
|
|
24
|
+
@social_account.unlink.should be_false
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'can be unlinked if the user has email/password and its the last social' do
|
|
28
|
+
@social_account = Fabricate(:social_account)
|
|
29
|
+
@user = @social_account.user
|
|
30
|
+
@user.email = "testing@email.test"
|
|
31
|
+
@user.password = "12345678"
|
|
32
|
+
@user.password_confirmation = "12345678"
|
|
33
|
+
@user.save
|
|
34
|
+
@social_account.unlink.should be_true
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe UserInvitation do
|
|
4
|
+
|
|
5
|
+
context "before save" do
|
|
6
|
+
|
|
7
|
+
context "if has no token" do
|
|
8
|
+
it 'should generate one' do
|
|
9
|
+
@user_invitation = UserInvitation.new(:email => "test@test.test", :roles => "user")
|
|
10
|
+
@user_invitation.save
|
|
11
|
+
@user_invitation.token.should_not be_nil
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
context "if has a token" do
|
|
16
|
+
it 'should not generate another token' do
|
|
17
|
+
@user_invitation = UserInvitation.new(:email => "test@test.test", :token => "oiaa09s1jiUHAS8danja9sja0")
|
|
18
|
+
@user_invitation.save
|
|
19
|
+
@user_invitation.reload
|
|
20
|
+
@user_invitation.token.should == "oiaa09s1jiUHAS8danja9sja0"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
context "before create" do
|
|
26
|
+
|
|
27
|
+
it 'should set sent_at' do
|
|
28
|
+
@user_invitation = UserInvitation.new(:email => "test@test.test", :roles => "user")
|
|
29
|
+
@user_invitation.save
|
|
30
|
+
@user_invitation.sent_at.should_not be_nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context "after create" do
|
|
36
|
+
|
|
37
|
+
it 'should send email' do
|
|
38
|
+
@user_invitation = UserInvitation.new(:email => "test@test.test", :roles => "user")
|
|
39
|
+
lambda{@user_invitation.save}.should change(ActionMailer::Base.deliveries, :size).by(1)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "find by invitation_token" do
|
|
45
|
+
before(:each) do
|
|
46
|
+
@user_invitation = Fabricate(:user_invitation)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'should return an user invitation' do
|
|
50
|
+
invitation_token = @user_invitation.id.to_s + @user_invitation.token
|
|
51
|
+
UserInvitation.find_by_invitation_token(invitation_token).class.should == UserInvitation
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it 'should return nil if token is invalid' do
|
|
55
|
+
invitation_token = '12389as9sudasdjasd9uaaiushdas9d'
|
|
56
|
+
UserInvitation.find_by_invitation_token(invitation_token).should be_nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context "accept" do
|
|
62
|
+
before(:each) do
|
|
63
|
+
@user_invitation = Fabricate(:user_invitation)
|
|
64
|
+
@account = Fabricate(:account)
|
|
65
|
+
@user = Fabricate(:user)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'should add user to account' do
|
|
69
|
+
@user_invitation.account_id = @account.id
|
|
70
|
+
@user_invitation.save
|
|
71
|
+
@user_invitation.accept(@user)
|
|
72
|
+
@account.account_users.find_by_user_id(@user.id).should_not be_nil
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it 'should raise error when account_id is invalid' do
|
|
76
|
+
@user_invitation.account_id = 2039812
|
|
77
|
+
@user_invitation.save
|
|
78
|
+
lambda { @user_invitation.accept(@user) }.should raise_error
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it 'should save invite roles on account_user' do
|
|
82
|
+
@user_invitation.account_id = @account.id
|
|
83
|
+
@user_invitation.roles =(["user", "guest"].join(','))
|
|
84
|
+
@user_invitation.save
|
|
85
|
+
@user_invitation.accept(@user)
|
|
86
|
+
AccountUser.last.is?('user').should be_true
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe User do
|
|
4
|
+
|
|
5
|
+
subject{ Fabricate(:user) }
|
|
6
|
+
|
|
7
|
+
it { should have_many(:account_users) }
|
|
8
|
+
it { should have_many(:accounts).through(:account_users) }
|
|
9
|
+
it { should have_many(:social_accounts) }
|
|
10
|
+
|
|
11
|
+
context "create_social" do
|
|
12
|
+
before do
|
|
13
|
+
@env = OmniAuth.config.mock_auth[:twitter]
|
|
14
|
+
@user = Fabricate(:user)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it 'should create a social for the user' do
|
|
18
|
+
@user.create_social(@env)
|
|
19
|
+
@user.social_accounts.empty?.should be_false
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
context "find_or_create_social" do
|
|
24
|
+
before do
|
|
25
|
+
@env = OmniAuth.config.mock_auth[:twitter]
|
|
26
|
+
@user = Fabricate(:user)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'should return the social if find' do
|
|
30
|
+
@user.create_social(@env)
|
|
31
|
+
@sa = @user.find_or_create_social(@env)
|
|
32
|
+
@sa.social_id.to_s.should == @env["uid"]
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context "find_or_create_by_social" do
|
|
37
|
+
before do
|
|
38
|
+
@env = OmniAuth.config.mock_auth[:twitter]
|
|
39
|
+
@facebook = OmniAuth.config.mock_auth[:facebook]
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'should create a new user with the social' do
|
|
43
|
+
user = User.find_or_create_by_social(@env)
|
|
44
|
+
user.social_accounts.first.social_id.to_s.should == @env["uid"]
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'should create a new user' do
|
|
48
|
+
user = User.find_or_create_by_social(@facebook)
|
|
49
|
+
user.social_accounts.first.social_id.to_s.should == @facebook["uid"]
|
|
50
|
+
user.email.should == @facebook["extra"]["raw_info"]["email"]
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'should find user with social' do
|
|
54
|
+
@user = Fabricate(:user)
|
|
55
|
+
@user.create_social(@env)
|
|
56
|
+
User.find_or_create_by_social(@env).should == @user
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'should update socials token' do
|
|
60
|
+
@user = Fabricate(:user)
|
|
61
|
+
@social = @user.create_social(@env)
|
|
62
|
+
@env['credentials']['token'] = "newtoken"
|
|
63
|
+
@user = User.find_or_create_by_social(@env)
|
|
64
|
+
@social.reload
|
|
65
|
+
@social.token.should == "newtoken"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
context "create" do
|
|
71
|
+
|
|
72
|
+
it 'should create an account for the user' do
|
|
73
|
+
user = User.create(:email => "test@email.test", :password => "secretpassword", :password_confirmation => "secretpassword")
|
|
74
|
+
user.accounts.empty?.should be_false
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it 'should no create an account if skip_create_account!' do
|
|
78
|
+
user = User.new(:email => "test@email.test", :password => "secretpassword", :password_confirmation => "secretpassword")
|
|
79
|
+
user.skip_create_account!
|
|
80
|
+
user.save
|
|
81
|
+
user.accounts.empty?.should be_true
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
context "default_account" do
|
|
87
|
+
before do
|
|
88
|
+
@user = Fabricate(:user)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
it 'should return an account' do
|
|
92
|
+
@user.default_account.class.should == Account
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
it 'should accept as account' do
|
|
96
|
+
@user.default_account(@user.accounts.first).class.should == Account
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
it 'should accept as account id' do
|
|
100
|
+
@user.default_account(@user.accounts.first.id).class.should == Account
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context "destruction_job method" do
|
|
106
|
+
before(:each) do
|
|
107
|
+
@user = Fabricate(:user)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'should return a job' do
|
|
111
|
+
@user.destroy
|
|
112
|
+
@user.destruction_job.class.should == Delayed::Backend::ActiveRecord::Job
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it 'should return null if account has no destruction job' do
|
|
116
|
+
@user.destruction_job.should be_nil
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
context "destrying? method" do
|
|
122
|
+
before(:each) do
|
|
123
|
+
@user = Fabricate(:user)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
it 'should return true if account has a destruction job' do
|
|
127
|
+
@user.destroy
|
|
128
|
+
@user.destroying?.should be_true
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
it 'should return false if account doesnt have a destruction job' do
|
|
132
|
+
@user.destroying?.should be_false
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
context "cancel_destruction" do
|
|
137
|
+
before(:each) do
|
|
138
|
+
@user = Fabricate(:user)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
it 'should cancel account destruction' do
|
|
142
|
+
@user.destroy
|
|
143
|
+
@user.cancel_destruction
|
|
144
|
+
@user.destroying?.should be_false
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it 'should return a job' do
|
|
148
|
+
@user.destroy
|
|
149
|
+
@user.cancel_destruction.class.should == Delayed::Backend::ActiveRecord::Job
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
it 'should return nil if doesnt have a destruction job' do
|
|
153
|
+
@user.cancel_destruction.should be_nil
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it 'should return nil if destruction job is locked' do
|
|
157
|
+
@user.destroy
|
|
158
|
+
job = @user.destruction_job
|
|
159
|
+
job.locked_at = Time.now
|
|
160
|
+
job.save
|
|
161
|
+
@user.cancel_destruction.should be_nil
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
context "is? method" do
|
|
167
|
+
before(:each) do
|
|
168
|
+
@user = Fabricate(:user)
|
|
169
|
+
@account = @user.accounts.first
|
|
170
|
+
@account_user = @account.account_users.find_by_user_id(@user.id)
|
|
171
|
+
@account_user.roles.destroy_all
|
|
172
|
+
@account_user.roles << AccountRole.create(:name => "user")
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
it 'should return true if user has the role for the account' do
|
|
176
|
+
@user.is?(:user, @account).should be_true
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
it 'should return if user hasnt the role for the account' do
|
|
180
|
+
@user.is?(:admin, @account).should be_false
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
end
|