Skip to content

Commit 333f161

Browse files
committed
Clean up users fixtures and update tests
Now that we have roles, we can target users more specifically for specific tests. We also don’t need some of the duplicate test fixtures. Issue #299
1 parent 4ab6c4b commit 333f161

File tree

10 files changed

+28
-40
lines changed

10 files changed

+28
-40
lines changed

test/controllers/accounts_controller_test.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
44
include Devise::Test::IntegrationHelpers
55

66
test "can get the setup page with a valid token" do
7-
user = users(:user1)
7+
user = users(:user)
88

99
token = user.set_reset_password_token
1010

@@ -21,7 +21,7 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
2121
end
2222

2323
test "cannot get setup page while logged in" do
24-
user = users(:user1)
24+
user = users(:user)
2525

2626
# Use a valid token to make this a legitimate test.
2727
# The redirection will run before the token is even checked, but we want to make sure it's an
@@ -36,7 +36,7 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
3636
end
3737

3838
test "can setup an account as a new user" do
39-
user = users(:user1)
39+
user = users(:user)
4040

4141
post create_account_path({
4242
reset_password_token: user.set_reset_password_token,
@@ -57,7 +57,7 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
5757
end
5858

5959
test "cannot setup an account with a previously-used token" do
60-
user = users(:user1)
60+
user = users(:user)
6161

6262
create_params = {
6363
reset_password_token: user.set_reset_password_token,
@@ -76,7 +76,7 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
7676
end
7777

7878
test "cannot setup an account with blank passwords" do
79-
user = users(:user1)
79+
user = users(:user)
8080

8181
post create_account_path({
8282
reset_password_token: user.set_reset_password_token,
@@ -87,7 +87,7 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
8787
end
8888

8989
test "cannot setup an account with short passwords" do
90-
user = users(:user1)
90+
user = users(:user)
9191
short_password = "password"[0, Devise.password_length.begin - 1]
9292

9393
post create_account_path({
@@ -99,7 +99,7 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
9999
end
100100

101101
test "cannot setup an account with mismatching passwords" do
102-
user = users(:user1)
102+
user = users(:user)
103103

104104
post create_account_path({
105105
reset_password_token: user.set_reset_password_token,

test/controllers/archive_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def after_all
2424
end
2525

2626
test "load index if authenticated" do
27-
sign_in users(:user1)
27+
sign_in users(:user)
2828
get root_url
2929
assert_response :success
3030
end

test/controllers/jobs_tracker_controller_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ class JobsTrackerControllerTest < ActionDispatch::IntegrationTest
44
include Devise::Test::IntegrationHelpers
55

66
test "can view jobs" do
7-
sign_in users(:user1)
7+
sign_in users(:user)
88
InstagramMediaSource.extract("https://www.instagram.com/p/CBcqOkyDDH8/", false)
99
get jobs_status_index_path
1010
assert_response :success
1111
end
1212

1313
test "can resubmit a scrape" do
14-
sign_in users(:user1)
14+
sign_in users(:user)
1515
scrape = Scrape.create({ fulfilled: false, url: "https://www.instagram.com/p/CBcqOkyDDH8/", scrape_type: :instagram })
1616
assert_not_nil scrape
1717

@@ -25,7 +25,7 @@ class JobsTrackerControllerTest < ActionDispatch::IntegrationTest
2525
end
2626

2727
test "can delete a scrape" do
28-
sign_in users(:user1)
28+
sign_in users(:user)
2929
scrape = Scrape.create({ fulfilled: false, url: "https://www.instagram.com/p/CBcqOkyDDH8/", scrape_type: :instagram })
3030
assert_not_nil scrape
3131

test/controllers/text_search_controller_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ArchiveControllerTest < ActionDispatch::IntegrationTest
1111
Sources::Tweet.create_from_url("https://twitter.com/ggreenwald/status/1430523746457112578")
1212
Sources::Tweet.create_from_url("https://twitter.com/bidenfoundation/status/1121446608040755200")
1313
Sources::Tweet.create_from_url("https://twitter.com/POTUS/status/1428115295756066824")
14-
sign_in users(:user1)
14+
sign_in users(:user)
1515

1616
# And then search
1717
get text_search_submit_url, params: { query: "Biden" }

test/fixtures/api_keys.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
#
77
one:
88
hashed_api_key: <%= ZenoEncryption.hash_string("123456789") %>
9-
user: user1
9+
user: user

test/fixtures/users.yml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,13 @@
1010
# two: {}
1111
# column: value
1212

13-
user1:
14-
15-
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>
16-
confirmed_at: <%= Time.now %>
17-
18-
user2:
19-
20-
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>
21-
confirmed_at: <%= Time.now %>
22-
23-
user3:
24-
25-
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>
26-
confirmed_at: <%= Time.now %>
27-
28-
existing_user:
29-
13+
user:
14+
3015
encrypted_password: <%= Devise::Encryptor.digest(User, 'password') %>
3116
confirmed_at: <%= Time.now %>
17+
roles:
18+
- insights_user
19+
- media_vault_user
3220

3321
new_user:
3422

test/helpers/accounts_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class AccountsHelperTest < ActionView::TestCase
44
include Devise::Test::IntegrationHelpers
55

66
test "search_history_helper" do
7-
sign_in users(:user1)
7+
sign_in users(:user)
88
TextSearch.create(query: "search term", user: User.first)
99
TextSearch.create(query: "another search term", user: User.first)
1010
TextSearch.create(query: "yet another search term", user: User.first)

test/models/api_key_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
class ApiKeyTest < ActiveSupport::TestCase
44
test "creating an api key returns the clear string of the key" do
5-
api_key = ApiKey.create(user: users(:user1))
5+
api_key = ApiKey.create(user: users(:user))
66
assert_not_nil api_key.api_key
77
assert_not_nil api_key.hashed_api_key
88
end
99

1010
test "retrieving an api key does not return the clear string of the key" do
11-
api_key = ApiKey.create(user: users(:user1))
11+
api_key = ApiKey.create(user: users(:user))
1212
api_key = ApiKey.find(api_key.id)
1313
assert_nil api_key.api_key
1414
assert_not_nil api_key.hashed_api_key

test/models/image_search_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class ImageSearchTest < ActiveSupport::TestCase
77
def setup
88
image_file = File.open("test/mocks/media/instagram_media_12765281-136d-4bfa-b7ad-e89f107b5769.jpg", binmode: true)
99
video_file = File.open("test/mocks/media/youtube_media_23b12624-2ef2-4dcb-97d2-966aa9fcba80.mp4", binmode: true)
10-
@image_search = ImageSearch.create!(image: image_file, user: users(:user1))
11-
@video_search = ImageSearch.create!(video: video_file, user: users(:user1))
10+
@image_search = ImageSearch.create!(image: image_file, user: users(:user))
11+
@video_search = ImageSearch.create!(video: video_file, user: users(:user))
1212

1313
Zelkova.graph.reset
1414
end

test/models/user_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class UserTest < ActiveSupport::TestCase
2929
end
3030

3131
test "should recognize users are not admins" do
32-
assert_not users(:existing_user).is_admin?
32+
assert_not users(:user).is_admin?
3333
end
3434

3535
test "can associate a user with an applicant" do
36-
user = users(:user1)
36+
user = users(:user)
3737
applicant = applicants(:approved)
3838

3939
user.update(applicant: applicant)
@@ -42,7 +42,7 @@ class UserTest < ActiveSupport::TestCase
4242
end
4343

4444
test "destroying user destroys applicant too" do
45-
user = users(:user1)
45+
user = users(:user)
4646
applicant = applicants(:approved)
4747

4848
user.update(applicant: applicant)
@@ -82,14 +82,14 @@ class UserTest < ActiveSupport::TestCase
8282
end
8383

8484
test "can create a reset password token" do
85-
user = users(:user1)
85+
user = users(:user)
8686
token = user.set_reset_password_token
8787

8888
assert token
8989
end
9090

9191
test "can look up a user with the reset token" do
92-
user = users(:user1)
92+
user = users(:user)
9393
token = user.set_reset_password_token
9494

9595
assert_equal user, User.with_reset_password_token(token)

0 commit comments

Comments
 (0)