tiny_passport 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/app/ables/tiny_passport/account_validate_able.rb +24 -0
  3. data/app/ables/tiny_passport/aggrement_term_able.rb +28 -0
  4. data/app/ables/tiny_passport/formable.rb +17 -0
  5. data/app/ables/tiny_passport/query_able.rb +25 -0
  6. data/app/controllers/tiny_passport/application_controller.rb +1 -0
  7. data/app/displays/tiny_passport/account_display.rb +25 -0
  8. data/app/displays/tiny_passport/oauth_login_display.rb +21 -0
  9. data/app/displays/tiny_passport/oauth_token_display.rb +25 -0
  10. data/app/errors/tiny_passport/alert_authorized_error.rb +6 -0
  11. data/app/errors/tiny_passport/unauthorized_error.rb +6 -0
  12. data/app/forms/tiny_passport/account_active_form.rb +83 -0
  13. data/app/forms/tiny_passport/account_form.rb +6 -0
  14. data/app/forms/tiny_passport/confirmation_token_form.rb +58 -0
  15. data/app/forms/tiny_passport/oauth/bind_connect_form.rb +65 -0
  16. data/app/forms/tiny_passport/oauth/bind_disconnect_form.rb +42 -0
  17. data/app/forms/tiny_passport/oauth/callback_form.rb +165 -0
  18. data/app/forms/tiny_passport/oauth/login_connect_form.rb +63 -0
  19. data/app/forms/tiny_passport/registration_form.rb +172 -0
  20. data/app/forms/tiny_passport/remember_token_auth_form.rb +32 -0
  21. data/app/forms/tiny_passport/reset_password_form.rb +95 -0
  22. data/app/forms/tiny_passport/reset_password_token_form.rb +55 -0
  23. data/app/forms/tiny_passport/session_form.rb +116 -0
  24. data/app/forms/tiny_passport/update_password_form.rb +50 -0
  25. data/app/forms/tiny_passport/welcome_email_form.rb +47 -0
  26. data/app/helpers/tiny_passport/application_helper.rb +1 -0
  27. data/app/mailers/tiny_passport/registration_mailer.rb +23 -0
  28. data/app/mailers/tiny_passport/reset_password_mailer.rb +16 -0
  29. data/app/models/concerns/tiny_passport/account_authenticatable.rb +24 -0
  30. data/app/models/tiny_passport/account.rb +41 -0
  31. data/app/models/tiny_passport/avatar.rb +6 -0
  32. data/app/models/tiny_passport/login_email.rb +89 -0
  33. data/app/models/tiny_passport/login_record.rb +69 -0
  34. data/app/models/tiny_passport/oauth_bind.rb +9 -0
  35. data/app/models/tiny_passport/oauth_info.rb +8 -0
  36. data/app/models/tiny_passport/oauth_login.rb +28 -0
  37. data/app/models/tiny_passport/oauth_token.rb +57 -0
  38. data/app/queries/tiny_passport/account_query.rb +45 -0
  39. data/app/services/tiny_passport/account_service.rb +43 -0
  40. data/app/services/tiny_passport/email_send_service.rb +32 -0
  41. data/app/services/tiny_passport/oauth_service.rb +11 -0
  42. data/app/views/layouts/tiny_passport/mailer.html.erb +7 -0
  43. data/app/views/tiny_passport/registration_mailer/send_confirmation_token.html.erb +5 -0
  44. data/app/views/tiny_passport/registration_mailer/welcome.html.erb +5 -0
  45. data/app/views/tiny_passport/reset_password_mailer/send_token.html.erb +5 -0
  46. data/config/locales/en/forms.en.yml +81 -0
  47. data/config/locales/zh-CN/forms.zh-CN.yml +123 -0
  48. data/config/routes.rb +1 -0
  49. data/db/migrate/20131105103853_create_tiny_passport_accounts.rb +23 -0
  50. data/db/migrate/20131105104415_create_tiny_passport_login_records.rb +20 -0
  51. data/db/migrate/20131105104559_create_tiny_passport_oauth_tokens.rb +27 -0
  52. data/db/migrate/20131105104632_create_tiny_passport_oauth_logins.rb +15 -0
  53. data/db/migrate/20131105104702_create_tiny_passport_oauth_binds.rb +16 -0
  54. data/db/migrate/20131105104738_create_tiny_passport_oauth_infos.rb +13 -0
  55. data/db/migrate/20131105104847_create_tiny_passport_avatars.rb +20 -0
  56. data/db/migrate/20131107031935_create_tiny_passport_login_emails.rb +25 -0
  57. data/lib/omniauth/strategies/qq_connect.rb +114 -0
  58. data/lib/tiny_passport/config.rb +72 -0
  59. data/lib/tiny_passport/engine.rb +16 -0
  60. data/lib/tiny_passport/http_authable.rb +50 -0
  61. data/lib/tiny_passport/http_authcenter.rb +138 -0
  62. data/lib/tiny_passport/mailerable.rb +20 -0
  63. data/lib/tiny_passport/omniauth/strategable.rb +21 -0
  64. data/lib/tiny_passport/version.rb +2 -1
  65. data/lib/tiny_passport.rb +13 -0
  66. data/test/dummy/app/controllers/application_controller.rb +1 -0
  67. data/test/dummy/app/helpers/application_helper.rb +1 -0
  68. data/test/dummy/config/application.rb +1 -0
  69. data/test/dummy/config/boot.rb +1 -0
  70. data/test/dummy/config/environment.rb +1 -0
  71. data/test/dummy/config/environments/development.rb +1 -0
  72. data/test/dummy/config/environments/production.rb +1 -0
  73. data/test/dummy/config/environments/test.rb +1 -0
  74. data/test/dummy/config/initializers/backtrace_silencers.rb +1 -0
  75. data/test/dummy/config/initializers/filter_parameter_logging.rb +1 -0
  76. data/test/dummy/config/initializers/inflections.rb +1 -0
  77. data/test/dummy/config/initializers/mime_types.rb +1 -0
  78. data/test/dummy/config/initializers/secret_token.rb +1 -0
  79. data/test/dummy/config/initializers/session_store.rb +1 -0
  80. data/test/dummy/config/initializers/wrap_parameters.rb +1 -0
  81. data/test/dummy/config/routes.rb +1 -0
  82. data/test/dummy/db/schema.rb +138 -0
  83. data/test/dummy/db/test.sqlite3 +0 -0
  84. data/test/dummy/log/test.log +15986 -0
  85. data/test/dummy/tmp/cache/271/2A1/tiny_cache%2Fmodels%2FTinyPassport%3A%3AAccount%2F1%2F1 +0 -0
  86. data/test/dummy/tmp/cache/EDF/4C1/tiny_cache%2Fmodel_uniq_keys%2FTinyPassport%3A%3ALoginEmail%2F%5B%5B%22account_id%22%2C+1%5D%5D +1 -0
  87. data/test/fixtures/tiny_passport/avatars.yml +23 -0
  88. data/test/fixtures/tiny_passport/login_emails.yml +23 -0
  89. data/test/fixtures/tiny_passport/login_records.yml +17 -0
  90. data/test/fixtures/tiny_passport/oauth_binds.yml +13 -0
  91. data/test/fixtures/tiny_passport/oauth_infos.yml +9 -0
  92. data/test/fixtures/tiny_passport/oauth_logins.yml +11 -0
  93. data/test/fixtures/tiny_passport/oauth_tokens.yml +21 -0
  94. data/test/fixtures/tiny_passport/users.yml +13 -0
  95. data/test/forms/tiny_passport/oauth/callback_form_test.rb +23 -0
  96. data/test/forms/tiny_passport/registration_form_test.rb +112 -0
  97. data/test/forms/tiny_passport/session_form_test.rb +139 -0
  98. data/test/forms/tiny_passport/update_password_form_test.rb +20 -0
  99. data/test/integration/navigation_test.rb +1 -0
  100. data/test/mailers/tiny_passport/registration_mailer_test.rb +10 -0
  101. data/test/mailers/tiny_passport/reset_password_mailer_test.rb +10 -0
  102. data/test/models/concerns/tiny_passport/configable_test.rb +46 -0
  103. data/test/models/tiny_passport/account_test.rb +8 -0
  104. data/test/models/tiny_passport/avatar_test.rb +10 -0
  105. data/test/models/tiny_passport/login_email_test.rb +10 -0
  106. data/test/models/tiny_passport/login_record_test.rb +10 -0
  107. data/test/models/tiny_passport/oauth_bind_test.rb +10 -0
  108. data/test/models/tiny_passport/oauth_info_test.rb +10 -0
  109. data/test/models/tiny_passport/oauth_login_test.rb +10 -0
  110. data/test/models/tiny_passport/oauth_token_test.rb +10 -0
  111. data/test/support/helpers.rb +66 -0
  112. data/test/test_helper.rb +24 -0
  113. data/test/tiny_passport_test.rb +1 -0
  114. metadata +257 -69
@@ -0,0 +1 @@
1
+ o: ActiveSupport::Cache::Entry: @valuei:@created_atf1390964231.656629:@expires_in0
@@ -0,0 +1,23 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ file: MyString
5
+ file_content_type: MyString
6
+ file_size: 1
7
+ file_name: MyString
8
+ origin_file_name: MyString
9
+ status_value: 1
10
+ owner_type: MyString
11
+ owner_id: 1
12
+ account_id: 1
13
+
14
+ two:
15
+ file: MyString
16
+ file_content_type: MyString
17
+ file_size: 1
18
+ file_name: MyString
19
+ origin_file_name: MyString
20
+ status_value: 1
21
+ owner_type: MyString
22
+ owner_id: 1
23
+ account_id: 1
@@ -0,0 +1,23 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
2
+
3
+ # This model initially had no columns defined. If you add columns to the
4
+ # model remove the '{}' from the fixture names and add the columns immediately
5
+ # below each fixture, per the syntax in the comments below
6
+ #
7
+ one:
8
+ value: MyString
9
+ confirmation_token: MyString
10
+ confirmed_at: 2013-11-05 18:42:34
11
+ confirmation_send_at: 2013-11-05 18:42:34
12
+ account_id: 1
13
+ deleted_at: 2013-11-05 18:42:34
14
+ status_value: 1
15
+
16
+ two:
17
+ value: MyString
18
+ confirmation_token: MyString
19
+ confirmed_at: 2013-11-05 18:42:34
20
+ confirmation_send_at: 2013-11-05 18:42:34
21
+ account_id: 1
22
+ deleted_at: 2013-11-05 18:42:34
23
+ status_value: 1
@@ -0,0 +1,17 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ account_id: 1
5
+ ip: MyString
6
+ way_value: 1
7
+ remembered: false
8
+ encrypted_remember_token: MyString
9
+ remember_expires_at: 2013-11-05 18:44:15
10
+
11
+ two:
12
+ account_id: 1
13
+ ip: MyString
14
+ way_value: 1
15
+ remembered: false
16
+ encrypted_remember_token: MyString
17
+ remember_expires_at: 2013-11-05 18:44:15
@@ -0,0 +1,13 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ oauth_token_id: 1
5
+ account_id: 1
6
+ status_value: 1
7
+ config_info_yaml: MyText
8
+
9
+ two:
10
+ oauth_token_id: 1
11
+ account_id: 1
12
+ status_value: 1
13
+ config_info_yaml: MyText
@@ -0,0 +1,9 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ oauth_token_id: 1
5
+ raw_info_yaml: MyText
6
+
7
+ two:
8
+ oauth_token_id: 1
9
+ raw_info_yaml: MyText
@@ -0,0 +1,11 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ oauth_token_id: 1
5
+ account_id: 1
6
+ status_value: 1
7
+
8
+ two:
9
+ oauth_token_id: 1
10
+ account_id: 1
11
+ status_value: 1
@@ -0,0 +1,21 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ strategy_type_value: 1
5
+ strategy_id: 1
6
+ access_token: MyString
7
+ access_secret: MyString
8
+ expires_at: 2013-11-05 18:45:59
9
+ origin_avatar_url: MyString
10
+ name: MyString
11
+ avatar_id: 1
12
+
13
+ two:
14
+ strategy_type_value: 1
15
+ strategy_id: 1
16
+ access_token: MyString
17
+ access_secret: MyString
18
+ expires_at: 2013-11-05 18:45:59
19
+ origin_avatar_url: MyString
20
+ name: MyString
21
+ avatar_id: 1
@@ -0,0 +1,13 @@
1
+ # Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
2
+
3
+ one:
4
+ login_name: "loginname"
5
+ avatar_id: nil
6
+ encrypted_password: ""
7
+ password_salt: ""
8
+ register_way_value: 0
9
+ deleted_at: nil
10
+ login_records_count: 0
11
+ current_login_failed_count: 0
12
+ login_failed_count: 0
13
+
@@ -0,0 +1,23 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ module Oauth
6
+ class CallbackFormTest < ActiveSupport::TestCase
7
+
8
+ context "QQ Login Callback" do
9
+ setup do
10
+ end
11
+
12
+ teardown do
13
+
14
+ end
15
+
16
+ should "callback success" do
17
+ form_1 = oauth_callback_with_params('login', {})
18
+ assert form_1.success?
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,112 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class RegistrationFormTest < ActiveSupport::TestCase
6
+ def generate_registration_registration_form_params params={}
7
+ @@generate_registration_registration_form_params_count ||= 0
8
+ @@generate_registration_registration_form_params_count += 1
9
+ count = @@generate_registration_registration_form_params_count
10
+
11
+ {
12
+ :login_name => "login_name_#{count}",
13
+ :login_email_value => "mail_#{count}@ruby1024.com",
14
+ :password => '123456',
15
+ :password_confirmation => '123456',
16
+ :agreement_terms => '1',
17
+ :created_ip => '127.0.0.1'
18
+ }.update(params)
19
+ end
20
+
21
+ context "validate" do
22
+ should 'submit success' do
23
+ @registration_form.submit(generate_registration_registration_form_params())
24
+ assert @registration_form.success?
25
+ end
26
+
27
+ context 'password' do
28
+ should 'present' do
29
+ @registration_form.submit(generate_registration_registration_form_params(
30
+ :password_confirmation => '',
31
+ :password => ''
32
+ ))
33
+ assert_equal @registration_form.errors.to_hash, {:password => ["can't be blank"]}
34
+
35
+ @registration_form.submit(generate_registration_registration_form_params(
36
+ :password_confirmation => '123456',
37
+ :password => ''
38
+ ))
39
+ assert_equal @registration_form.errors.to_hash, {:password=>["can't be blank"], :password_confirmation=>["doesn't match Password"]}
40
+ end
41
+
42
+ should 'match the password_confirmation' do
43
+ @registration_form.submit(generate_registration_registration_form_params(
44
+ :password_confirmation => '1234567',
45
+ :password => '123456'
46
+ ))
47
+ assert_equal @registration_form.errors.to_hash, {:password_confirmation=>["doesn't match Password"]}
48
+ end
49
+ end
50
+
51
+ context 'login_email_value' do
52
+ should 'present' do
53
+ @registration_form.submit(generate_registration_registration_form_params(
54
+ :login_email_value => ''
55
+ ))
56
+
57
+ assert_equal @registration_form.errors[:login_email_value], ['is invalid']
58
+ end
59
+ end
60
+
61
+ context 'created_ip' do
62
+ should 'present' do
63
+ @registration_form.submit(generate_registration_registration_form_params(
64
+ :created_ip => ''
65
+ ))
66
+
67
+ assert_equal @registration_form.errors[:created_ip], ["can't be blank"]
68
+ end
69
+ end
70
+
71
+ context 'login_name' do
72
+ should 'present' do
73
+ @registration_form.submit(generate_registration_registration_form_params(
74
+ :login_name => ''
75
+ ))
76
+
77
+ assert_equal @registration_form.errors[:login_name], ["can't be blank"]
78
+ end
79
+
80
+ should 'lengh' do
81
+ @registration_form.submit(generate_registration_registration_form_params(
82
+ :login_name => 'ab'
83
+ ))
84
+ assert_equal @registration_form.errors[:login_name], ["is too short (minimum is 3 characters)"]
85
+
86
+ @registration_form.submit(generate_registration_registration_form_params(
87
+ :login_name => 'abcedfghijklmnopqrst'
88
+ ))
89
+ assert_equal @registration_form.errors[:login_name], ["is too long (maximum is 18 characters)"]
90
+ end
91
+ end
92
+
93
+ context 'agreement_terms' do
94
+ should 'be agreed' do
95
+ @registration_form.submit(generate_registration_registration_form_params(
96
+ :agreement_terms => '0'
97
+ ))
98
+ assert_equal @registration_form.errors[:agreement_terms], ["Please Agree with our agreement"]
99
+
100
+ @registration_form.submit(generate_registration_registration_form_params().except(:agreement_terms))
101
+ assert_equal @registration_form.errors[:agreement_terms], ["Please Agree with our agreement"]
102
+ end
103
+ end
104
+
105
+ setup do
106
+ @registration_form = ::TinyPassport::RegistrationForm.new
107
+ end
108
+ end
109
+
110
+ end
111
+ end
112
+
@@ -0,0 +1,139 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class SessionFormTest < ActiveSupport::TestCase
6
+ def generate_session_form_params params={}
7
+ @@generate_session_form_params_count ||= 0
8
+ @@generate_session_form_params_count += 1
9
+ count = @@generate_session_form_params_count
10
+
11
+ {
12
+ :input_value => "login_name#{count}",
13
+ :password => "password",
14
+ :remembered => '1',
15
+ :ip => '127.0.0.1'
16
+ }.update(params)
17
+ end
18
+
19
+ context '#submit' do
20
+ setup do
21
+ ::TinyPassport::LoginEmail.last.status_active_verify!
22
+ end
23
+
24
+ context 'fail' do
25
+ should 'when login_name error' do
26
+ @session_form.submit(generate_session_form_params(
27
+ :input_value => 'errorname',
28
+ :password => 'password'
29
+ ))
30
+ assert_equal @session_form.errors.to_hash, {:input_value => ["login name not exists"]}
31
+ end
32
+
33
+ should 'when login_email_value error' do
34
+ @session_form.submit(generate_session_form_params(
35
+ :input_value => 'errorname@error.com',
36
+ :password => 'password'
37
+ ))
38
+ assert_equal @session_form.errors.to_hash, {:input_value => ["email not exists"]}
39
+ end
40
+ end
41
+
42
+ context 'sucess' do
43
+ context 'remembered true' do
44
+ should 'ok' do
45
+ @session_form.submit(generate_session_form_params(
46
+ :input_value => 'login_name_1',
47
+ :password => 'password',
48
+ :remembered => true
49
+ ))
50
+ assert @session_form.success?
51
+
52
+ login_record = @session_form.result[:login_record]
53
+ assert login_record.remembered
54
+ end
55
+ end
56
+
57
+ context 'when remembered false' do
58
+ should 'ok' do
59
+ @session_form.submit(generate_session_form_params(
60
+ :input_value => 'login_name_1',
61
+ :password => 'password',
62
+ :remembered => false
63
+ ))
64
+ assert @session_form.success?
65
+
66
+ login_record = @session_form.result[:login_record]
67
+ assert_equal login_record.remembered, false
68
+ end
69
+ end
70
+
71
+ should 'when login name input' do
72
+ @session_form.submit(generate_session_form_params(
73
+ :input_value => 'login_name_1',
74
+ :password => 'password'
75
+ ))
76
+ assert @session_form.success?
77
+ end
78
+
79
+ should 'when login email input' do
80
+ @session_form.submit(generate_session_form_params(
81
+ :input_value => 'mail_1@ruby1024.com',
82
+ :password => 'password'
83
+ ))
84
+ assert @session_form.success?
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ context "validate" do
91
+ context 'input value' do
92
+ should 'present' do
93
+ @session_form.submit(generate_session_form_params(
94
+ :input_value => '',
95
+ :password => 'password'
96
+ ))
97
+ assert_equal @session_form.errors.to_hash, {:input_value => ["can't be blank"]}
98
+ end
99
+
100
+ should 'when login email not actived' do
101
+ @session_form.submit(generate_session_form_params(
102
+ :input_value => 'mail_1@ruby1024.com',
103
+ :password => 'password'
104
+ ))
105
+ assert_equal @session_form.errors.to_hash, {:input_value => ['email not active']}
106
+ end
107
+ end
108
+
109
+ context 'password' do
110
+ should 'present' do
111
+ @session_form.submit(generate_session_form_params(
112
+ :input_value => 'login_name_x',
113
+ :password => ''
114
+ ))
115
+ assert_equal @session_form.errors.to_hash, {:password => ["can't be blank"]}
116
+ end
117
+ end
118
+ end
119
+
120
+ setup do
121
+ Rails.cache.clear
122
+ @registration_form = ::TinyPassport::RegistrationForm.new
123
+
124
+ register_params = {
125
+ :login_name => "login_name_1",
126
+ :login_email_value => "mail_1@ruby1024.com",
127
+ :password => 'password',
128
+ :password_confirmation => 'password',
129
+ :agreement_terms => '1',
130
+ :created_ip => '127.0.0.1'
131
+ }
132
+
133
+ @registration_form.submit(register_params)
134
+
135
+ @session_form = ::TinyPassport::SessionForm.new
136
+ end
137
+ end
138
+ end
139
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class UpdatePasswordFormTest < ActiveSupport::TestCase
6
+ def generate_update_password_form_params params={}
7
+ @@generate_update_password_form_params_count ||= 0
8
+ @@generate_update_password_form_params_count += 1
9
+ count = @@generate_update_password_form_params_count
10
+
11
+ # {
12
+ # :input_value => "login_name#{count}",
13
+ # :password => "password",
14
+ # :remembered => '1',
15
+ # :ip => '127.0.0.1'
16
+ # }.update(params)
17
+ end
18
+
19
+ end
20
+ end
@@ -1,3 +1,4 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'test_helper'
2
3
 
3
4
  class NavigationTest < ActionDispatch::IntegrationTest
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class RegistrationMailerTest < ActionMailer::TestCase
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class ResetPasswordMailerTest < ActionMailer::TestCase
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+ end
@@ -0,0 +1,46 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module Concerns
5
+ module TinyPassport
6
+
7
+ class HoHoConfigAccount
8
+ attr_accessor :status_value
9
+
10
+ include ::TinySupport::Configable
11
+
12
+ def self.scope *args
13
+ end
14
+
15
+ self.tiny_support_config :status, [
16
+ {:key => 'default', :value => 0, :desc => "HelloDefault"},
17
+ {:key => 'init', :value => 1, :desc => "HelloInit"},
18
+ {:key => 'publish', :value => 2, :desc => "HelloPublish"},
19
+ {:key => 'block', :value => 3, :desc => "HelloBlock"},
20
+ {:key => 'deleted', :value => 4, :desc => "HelloDeleted"}
21
+ ]
22
+
23
+ end
24
+
25
+ class ConfigableTest < ActiveSupport::TestCase
26
+ test "HoHoConfigAccount.status_config defined" do
27
+ assert defined?(HoHoConfigAccount.status_config)
28
+
29
+ a_account = HoHoConfigAccount.new
30
+ a_account.status_value = 1
31
+ assert_equal a_account.status.key, 'init'
32
+ assert a_account.status_key?('init')
33
+ assert_equal a_account.status_key?('publish'), false
34
+ assert_equal a_account.status_key?('block'), false
35
+ assert_equal a_account.status_key?('none'), false
36
+
37
+ b_account = HoHoConfigAccount.new
38
+ b_account.status_value = -1
39
+ assert_equal b_account.status.key, 'default'
40
+ assert_equal b_account.status.desc, 'HelloDefault'
41
+
42
+ end
43
+
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class AccountTest < ActiveSupport::TestCase
6
+
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class AvatarTest < ActiveSupport::TestCase
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class LoginEmailTest < ActiveSupport::TestCase
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class LoginRecordTest < ActiveSupport::TestCase
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class OauthBindTest < ActiveSupport::TestCase
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class OauthInfoTest < ActiveSupport::TestCase
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class OauthLoginTest < ActiveSupport::TestCase
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ module TinyPassport
5
+ class OauthTokenTest < ActiveSupport::TestCase
6
+ # test "the truth" do
7
+ # assert true
8
+ # end
9
+ end
10
+ end
@@ -0,0 +1,66 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'active_support/test_case'
3
+
4
+ class ActiveSupport::TestCase
5
+
6
+ # 生成一个唯一的邮箱
7
+ def generate_unique_email
8
+ @@email_count ||= 0
9
+ @@email_count += 1
10
+ "test#{@@email_count}@example.com"
11
+ end
12
+
13
+ def generate_unique_login_name
14
+ @@login_name_count ||= 0
15
+ @@login_name_count += 1
16
+ "loginname#{@@login_name_count}"
17
+ end
18
+
19
+ def oauth_callback_with_params(usage, params={})
20
+ @@oauth_callback_with_params_count ||= 0
21
+ @@oauth_callback_with_params_count += 1
22
+
23
+ count = @@oauth_callback_with_params_count
24
+
25
+ attrs = {
26
+ "provider" => "qq_connect",
27
+ "uid" => "51173C8FCF304708D299C1EE00A7B#{count}",
28
+ "info" => {
29
+ "nick_name" => "Happy#{count}",
30
+ "name" => "Happy#{count}",
31
+ "avatar" => "http://qzapp.qlogo.cn/qzapp/100587827/51173C8FCF304708D299C1EE00A7BB6A/100",
32
+ "gender" => 1
33
+ },
34
+ "credentials" => {
35
+ "token" => "71A81CB1FCB726C791D985C5AA117338",
36
+ "refresh_token" => "A3F01B40632B2C39262FA5F02981BC0A",
37
+ "expires_at" => 1396189038,
38
+ "expires" => true
39
+ },
40
+ "extra" => {
41
+ "raw_info" => {
42
+ "ret" => 0,
43
+ "msg" => "",
44
+ "is_lost" => 0,
45
+ "nickname" => "Happy#{count}",
46
+ "gender" => "男",
47
+ "figureurl" => "http://qzapp.qlogo.cn/qzapp/100587827/51173C8FCF304708D299C1EE00A7BB6A/30",
48
+ "figureurl_1" => "http://qzapp.qlogo.cn/qzapp/100587827/51173C8FCF304708D299C1EE00A7BB6A/50",
49
+ "figureurl_2" => "http://qzapp.qlogo.cn/qzapp/100587827/51173C8FCF304708D299C1EE00A7BB6A/100",
50
+ "figureurl_qq_1" => "http://q.qlogo.cn/qqapp/100587827/51173C8FCF304708D299C1EE00A7BB6A/40",
51
+ "figureurl_qq_2" => "http://q.qlogo.cn/qqapp/100587827/51173C8FCF304708D299C1EE00A7BB6A/100",
52
+ "is_yellow_vip" => "0",
53
+ "vip" => "0",
54
+ "yellow_vip_level" => "0",
55
+ "level" => "0",
56
+ "is_yellow_year_vip" => "0"
57
+ }
58
+ }
59
+ }.deep_merge(params)
60
+
61
+ form = ::TinyPassport::Oauth::CallbackForm.new
62
+ form.submit(usage, {:ip => '192.168.6.246'}, attrs)
63
+ form
64
+ end
65
+
66
+ end