devise_token_auth 0.1.21.alpha1 → 0.1.21.alpha2

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.
@@ -7,156 +7,158 @@ require 'test_helper'
7
7
  # was the appropriate message delivered in the json payload?
8
8
 
9
9
  class DeviseTokenAuth::RegistrationsControllerTest < ActionController::TestCase
10
- describe DeviseTokenAuth::RegistrationsController, "Successful registration" do
11
- before do
12
- xhr :post, :create, {
13
- email: -> { Faker::Internet.email },
14
- password: "secret123",
15
- password_confirmation: "secret123",
16
- confirm_success_url: -> { Faker::Internet.url }
17
- }
18
-
19
- @user = assigns(:resource)
20
- @data = JSON.parse(response.body)
21
- @mail = ActionMailer::Base.deliveries.last
22
- end
23
-
24
- test "request should be successful" do
25
- assert_equal 200, response.status
26
- end
27
-
28
- test "user should have been created" do
29
- assert @user.id
30
- end
31
-
32
- test "user should not be confirmed" do
33
- assert_nil @user.confirmed_at
34
- end
35
-
36
- test "new user data should be returned as json" do
37
- assert @data['data']['email']
38
- end
39
-
40
- test "new user should receive confirmation email" do
41
- assert_equal @user.email, @mail['to'].to_s
42
- end
43
-
44
- test "new user password should not be returned" do
45
- assert_nil @data['data']['password']
46
- end
47
- end
48
-
49
- describe DeviseTokenAuth::RegistrationsController, "Mismatched passwords" do
50
- before do
51
- xhr :post, :create, {
52
- email: -> { Faker::Internet.email },
53
- password: "secret123",
54
- password_confirmation: "bogus",
55
- confirm_success_url: -> { Faker::Internet.url }
56
- }
57
-
58
- @user = assigns(:resource)
59
- @data = JSON.parse(response.body)
60
- end
61
-
62
- test "request should not be successful" do
63
- assert_equal 403, response.status
64
- end
65
-
66
- test "user should have been created" do
67
- assert_nil @user.id
68
- end
69
-
70
- test "error should be returned in the response" do
71
- assert @data['errors'].length
72
- end
73
- end
74
-
75
- describe DeviseTokenAuth::RegistrationsController, "Existing users" do
76
- before do
77
- @existing_user = users(:confirmed_email_user)
10
+ describe DeviseTokenAuth::RegistrationsController do
11
+ describe "Successful registration" do
12
+ before do
13
+ xhr :post, :create, {
14
+ email: -> { Faker::Internet.email },
15
+ password: "secret123",
16
+ password_confirmation: "secret123",
17
+ confirm_success_url: -> { Faker::Internet.url }
18
+ }
19
+
20
+ @user = assigns(:resource)
21
+ @data = JSON.parse(response.body)
22
+ @mail = ActionMailer::Base.deliveries.last
23
+ end
24
+
25
+ test "request should be successful" do
26
+ assert_equal 200, response.status
27
+ end
28
+
29
+ test "user should have been created" do
30
+ assert @user.id
31
+ end
78
32
 
79
- xhr :post, :create, {
80
- email: @existing_user.email,
81
- password: "secret123",
82
- password_confirmation: "secret123",
83
- confirm_success_url: -> { Faker::Internet.url }
84
- }
33
+ test "user should not be confirmed" do
34
+ assert_nil @user.confirmed_at
35
+ end
36
+
37
+ test "new user data should be returned as json" do
38
+ assert @data['data']['email']
39
+ end
40
+
41
+ test "new user should receive confirmation email" do
42
+ assert_equal @user.email, @mail['to'].to_s
43
+ end
44
+
45
+ test "new user password should not be returned" do
46
+ assert_nil @data['data']['password']
47
+ end
48
+ end
49
+
50
+ describe "Mismatched passwords" do
51
+ before do
52
+ xhr :post, :create, {
53
+ email: -> { Faker::Internet.email },
54
+ password: "secret123",
55
+ password_confirmation: "bogus",
56
+ confirm_success_url: -> { Faker::Internet.url }
57
+ }
58
+
59
+ @user = assigns(:resource)
60
+ @data = JSON.parse(response.body)
61
+ end
62
+
63
+ test "request should not be successful" do
64
+ assert_equal 403, response.status
65
+ end
66
+
67
+ test "user should have been created" do
68
+ assert_nil @user.id
69
+ end
70
+
71
+ test "error should be returned in the response" do
72
+ assert @data['errors'].length
73
+ end
74
+ end
75
+
76
+ describe "Existing users" do
77
+ before do
78
+ @existing_user = users(:confirmed_email_user)
79
+
80
+ xhr :post, :create, {
81
+ email: @existing_user.email,
82
+ password: "secret123",
83
+ password_confirmation: "secret123",
84
+ confirm_success_url: -> { Faker::Internet.url }
85
+ }
86
+
87
+ @user = assigns(:resource)
88
+ @data = JSON.parse(response.body)
89
+ end
90
+
91
+ test "request should not be successful" do
92
+ assert_equal 403, response.status
93
+ end
94
+
95
+ test "user should have been created" do
96
+ assert_nil @user.id
97
+ end
98
+
99
+ test "error should be returned in the response" do
100
+ assert @data['errors'].length
101
+ end
102
+ end
103
+
104
+
105
+ describe "Ouath user has existing email" do
106
+ before do
107
+ @existing_user = users(:duplicate_email_facebook_user)
108
+
109
+ xhr :post, :create, {
110
+ email: @existing_user.email,
111
+ password: "secret123",
112
+ password_confirmation: "secret123",
113
+ confirm_success_url: -> { Faker::Internet.url }
114
+ }
115
+
116
+ @user = assigns(:resource)
117
+ @data = JSON.parse(response.body)
118
+ end
85
119
 
86
- @user = assigns(:resource)
87
- @data = JSON.parse(response.body)
88
- end
89
-
90
- test "request should not be successful" do
91
- assert_equal 403, response.status
92
- end
93
-
94
- test "user should have been created" do
95
- assert_nil @user.id
96
- end
97
-
98
- test "error should be returned in the response" do
99
- assert @data['errors'].length
100
- end
101
- end
102
-
103
-
104
- describe DeviseTokenAuth::RegistrationsController, "Ouath user has existing email" do
105
- before do
106
- @existing_user = users(:duplicate_email_facebook_user)
107
-
108
- xhr :post, :create, {
109
- email: @existing_user.email,
110
- password: "secret123",
111
- password_confirmation: "secret123",
112
- confirm_success_url: -> { Faker::Internet.url }
113
- }
114
-
115
- @user = assigns(:resource)
116
- @data = JSON.parse(response.body)
117
- end
118
-
119
- test "request should be successful" do
120
- assert_equal 200, response.status
121
- end
122
-
123
- test "user should have been created" do
124
- assert @user.id
125
- end
126
-
127
- test "new user data should be returned as json" do
128
- assert @data['data']['email']
129
- end
130
- end
131
-
132
- describe DeviseTokenAuth::RegistrationsController, "Alternate user class" do
133
- setup do
134
- @request.env['devise.mapping'] = Devise.mappings[:mang]
135
- end
120
+ test "request should be successful" do
121
+ assert_equal 200, response.status
122
+ end
136
123
 
137
- teardown do
138
- @request.env['devise.mapping'] = Devise.mappings[:user]
139
- end
124
+ test "user should have been created" do
125
+ assert @user.id
126
+ end
140
127
 
141
- before do
142
- xhr :post, :create, {
143
- email: -> { Faker::Internet.email },
144
- password: "secret123",
145
- password_confirmation: "secret123",
146
- confirm_success_url: -> { Faker::Internet.url }
147
- }
148
-
149
- @user = assigns(:resource)
150
- @data = JSON.parse(response.body)
151
- @mail = ActionMailer::Base.deliveries.last
128
+ test "new user data should be returned as json" do
129
+ assert @data['data']['email']
130
+ end
152
131
  end
153
132
 
154
- test "request should be successful" do
155
- assert_equal 200, response.status
156
- end
133
+ describe "Alternate user class" do
134
+ setup do
135
+ @request.env['devise.mapping'] = Devise.mappings[:mang]
136
+ end
137
+
138
+ teardown do
139
+ @request.env['devise.mapping'] = Devise.mappings[:user]
140
+ end
141
+
142
+ before do
143
+ xhr :post, :create, {
144
+ email: -> { Faker::Internet.email },
145
+ password: "secret123",
146
+ password_confirmation: "secret123",
147
+ confirm_success_url: -> { Faker::Internet.url }
148
+ }
149
+
150
+ @user = assigns(:resource)
151
+ @data = JSON.parse(response.body)
152
+ @mail = ActionMailer::Base.deliveries.last
153
+ end
154
+
155
+ test "request should be successful" do
156
+ assert_equal 200, response.status
157
+ end
157
158
 
158
- test "use should be a Mang" do
159
- assert_equal "Mang", @user.class.name
159
+ test "use should be a Mang" do
160
+ assert_equal "Mang", @user.class.name
161
+ end
160
162
  end
161
163
  end
162
164
  end
@@ -7,40 +7,81 @@ require 'test_helper'
7
7
  # was the appropriate message delivered in the json payload?
8
8
 
9
9
  class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
10
- describe DeviseTokenAuth::SessionsController, "Confirmed user" do
11
- before do
12
- @existing_user = users(:confirmed_email_user)
13
- @existing_user.skip_confirmation!
14
- @existing_user.save!
10
+ describe DeviseTokenAuth::SessionsController do
11
+ describe "Confirmed user" do
12
+ before do
13
+ @existing_user = users(:confirmed_email_user)
14
+ @existing_user.skip_confirmation!
15
+ @existing_user.save!
16
+ end
17
+
18
+ describe 'success' do
19
+ before do
20
+ xhr :post, :create, {
21
+ email: @existing_user.email,
22
+ password: 'secret123'
23
+ }
24
+
25
+ @user = assigns(:user)
26
+ @data = JSON.parse(response.body)
27
+ end
28
+
29
+ test "request should succeed" do
30
+ assert_equal 200, response.status
31
+ end
32
+
33
+ test "request should return user data" do
34
+ assert_equal @existing_user.email, @data['data']['email']
35
+ end
36
+ end
37
+
38
+ describe 'failure' do
39
+ before do
40
+ xhr :post, :create, {
41
+ email: @existing_user.email,
42
+ password: 'bogus'
43
+ }
44
+
45
+ @user = assigns(:user)
46
+ @data = JSON.parse(response.body)
47
+ end
48
+
49
+ test "request should fail" do
50
+ assert_equal 401, response.status
51
+ end
52
+
53
+ test "response should contain errors" do
54
+ assert @data['errors']
55
+ end
56
+ end
15
57
  end
16
58
 
17
- describe 'success' do
59
+ describe "Unconfirmed user" do
18
60
  before do
61
+ @unconfirmed_user = users(:unconfirmed_email_user)
19
62
  xhr :post, :create, {
20
- email: @existing_user.email,
63
+ email: @unconfirmed_user.email,
21
64
  password: 'secret123'
22
65
  }
23
-
24
66
  @user = assigns(:user)
25
67
  @data = JSON.parse(response.body)
26
68
  end
27
69
 
28
- test "request should succeed" do
29
- assert_equal 200, response.status
70
+ test "request should fail" do
71
+ assert_equal 401, response.status
30
72
  end
31
73
 
32
- test "request should return user data" do
33
- assert_equal @existing_user.email, @data['data']['email']
74
+ test "response should contain errors" do
75
+ assert @data['errors']
34
76
  end
35
77
  end
36
78
 
37
- describe 'failure' do
79
+ describe "Non-existing user" do
38
80
  before do
39
81
  xhr :post, :create, {
40
- email: @existing_user.email,
41
- password: 'bogus'
82
+ email: -> { Faker::Internet.email },
83
+ password: -> { Faker::Number.number(10) }
42
84
  }
43
-
44
85
  @user = assigns(:user)
45
86
  @data = JSON.parse(response.body)
46
87
  end
@@ -53,76 +94,37 @@ class DeviseTokenAuth::SessionsControllerTest < ActionController::TestCase
53
94
  assert @data['errors']
54
95
  end
55
96
  end
56
- end
57
-
58
- describe DeviseTokenAuth::SessionsController, "Unconfirmed user" do
59
- before do
60
- @unconfirmed_user = users(:unconfirmed_email_user)
61
- xhr :post, :create, {
62
- email: @unconfirmed_user.email,
63
- password: 'secret123'
64
- }
65
- @user = assigns(:user)
66
- @data = JSON.parse(response.body)
67
- end
68
97
 
69
- test "request should fail" do
70
- assert_equal 401, response.status
71
- end
72
-
73
- test "response should contain errors" do
74
- assert @data['errors']
75
- end
76
- end
77
-
78
- describe DeviseTokenAuth::SessionsController, "Non-existing user" do
79
- before do
80
- xhr :post, :create, {
81
- email: -> { Faker::Internet.email },
82
- password: -> { Faker::Number.number(10) }
83
- }
84
- @user = assigns(:user)
85
- @data = JSON.parse(response.body)
86
- end
87
-
88
- test "request should fail" do
89
- assert_equal 401, response.status
90
- end
91
-
92
- test "response should contain errors" do
93
- assert @data['errors']
94
- end
95
- end
96
-
97
- describe DeviseTokenAuth::SessionsController, "Alternate user class" do
98
- setup do
99
- @request.env['devise.mapping'] = Devise.mappings[:mang]
100
- end
98
+ describe "Alternate user class" do
99
+ setup do
100
+ @request.env['devise.mapping'] = Devise.mappings[:mang]
101
+ end
101
102
 
102
- teardown do
103
- @request.env['devise.mapping'] = Devise.mappings[:user]
104
- end
103
+ teardown do
104
+ @request.env['devise.mapping'] = Devise.mappings[:user]
105
+ end
105
106
 
106
- before do
107
- @existing_user = mangs(:confirmed_email_user)
108
- @existing_user.skip_confirmation!
109
- @existing_user.save!
107
+ before do
108
+ @existing_user = mangs(:confirmed_email_user)
109
+ @existing_user.skip_confirmation!
110
+ @existing_user.save!
110
111
 
111
- xhr :post, :create, {
112
- email: @existing_user.email,
113
- password: 'secret123'
114
- }
112
+ xhr :post, :create, {
113
+ email: @existing_user.email,
114
+ password: 'secret123'
115
+ }
115
116
 
116
- @user = assigns(:user)
117
- @data = JSON.parse(response.body)
118
- end
117
+ @user = assigns(:user)
118
+ @data = JSON.parse(response.body)
119
+ end
119
120
 
120
- test "request should succeed" do
121
- assert_equal 200, response.status
122
- end
121
+ test "request should succeed" do
122
+ assert_equal 200, response.status
123
+ end
123
124
 
124
- test "request should return user data" do
125
- assert_equal @existing_user.email, @data['data']['email']
125
+ test "request should return user data" do
126
+ assert_equal @existing_user.email, @data['data']['email']
127
+ end
126
128
  end
127
129
  end
128
130
  end