summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2017-12-08 18:27:24 +0100
committerAzul <azul@riseup.net>2017-12-08 21:33:09 +0100
commitd839bed40fb7901ea88395d4ba06e58f4b3cc88a (patch)
tree5939690ac0f0f2226459aa9412a80292515ebae2 /test
parentff8b2635c308d45ec38fd4eed257db7da9b3c4b0 (diff)
upgrade: factory_girl -> factory_bot
Diffstat (limited to 'test')
-rw-r--r--test/factories.rb2
-rw-r--r--test/functional/api/identities_controller_test.rb7
-rw-r--r--test/functional/api/messages_controller_test.rb13
-rw-r--r--test/functional/api/users_controller_test.rb4
-rw-r--r--test/functional/identities_controller_test.rb16
-rw-r--r--test/integration/api/pgp_key_test.rb2
-rw-r--r--test/integration/browser/account_livecycle_test.rb2
-rw-r--r--test/integration/browser/admin_test.rb2
-rw-r--r--test/integration/browser/security_test.rb2
-rw-r--r--test/support/api_integration_test.rb2
-rw-r--r--test/support/browser_integration_test.rb2
-rw-r--r--test/support/stub_record_helper.rb4
-rw-r--r--test/unit/account_test.rb7
-rw-r--r--test/unit/invite_code_validator_test.rb17
-rw-r--r--test/unit/token_test.rb17
-rw-r--r--test/unit/user_test.rb6
16 files changed, 58 insertions, 47 deletions
diff --git a/test/factories.rb b/test/factories.rb
index 5d49729..f287842 100644
--- a/test/factories.rb
+++ b/test/factories.rb
@@ -3,7 +3,7 @@ Dir.glob(ENGINE_FACTORY_FILES) do |factory_file|
require factory_file
end
-FactoryGirl.define do
+FactoryBot.define do
factory :user do
# Faker::Internet.user_name alone was sometimes
diff --git a/test/functional/api/identities_controller_test.rb b/test/functional/api/identities_controller_test.rb
index 57345c8..bb5608e 100644
--- a/test/functional/api/identities_controller_test.rb
+++ b/test/functional/api/identities_controller_test.rb
@@ -4,7 +4,7 @@ class Api::IdentitiesControllerTest < ApiControllerTest
test "api monitor can fetch identity" do
monitor_auth do
- identity = FactoryGirl.create :identity
+ identity = create_identity
api_get :show, :id => identity.address, :format => 'json'
assert_response :success
assert_equal identity, assigns(:identity)
@@ -16,9 +16,12 @@ class Api::IdentitiesControllerTest < ApiControllerTest
test "anonymous cannot fetch identity" do
- identity = FactoryGirl.create :identity
+ identity = create_identity
api_get :show, :id => identity.address, :format => 'json'
assert_response :forbidden
end
+ def create_identity
+ FactoryBot.create :identity
+ end
end
diff --git a/test/functional/api/messages_controller_test.rb b/test/functional/api/messages_controller_test.rb
index e586980..31ba2b0 100644
--- a/test/functional/api/messages_controller_test.rb
+++ b/test/functional/api/messages_controller_test.rb
@@ -2,17 +2,12 @@ require 'test_helper'
class Api::MessagesControllerTest < ApiControllerTest
- setup do
- @user = FactoryGirl.build(:user)
- @user.save
- end
-
# NOTE: the available languages for test are :en and :de
# so :es will result in english response.
test "get the motd" do
with_config("customization_directory" => Rails.root+'test/files') do
- login @user
+ login
api_get :index, :locale => 'es'
body = JSON.parse(response.body)
message1 = "<p>\"This\" is a <strong>very</strong> fine message. <a href=\"https://bitmask.net\">https://bitmask.net</a></p>\n"
@@ -23,7 +18,7 @@ class Api::MessagesControllerTest < ApiControllerTest
test "get localized motd" do
with_config("customization_directory" => Rails.root+'test/files') do
- login @user
+ login
api_get :index, :locale => 'de'
body = JSON.parse(response.body)
message1 = "<p>Dies ist eine sehr feine Nachricht. <a href=\"https://bitmask.net\">https://bitmask.net</a></p>\n"
@@ -32,7 +27,7 @@ class Api::MessagesControllerTest < ApiControllerTest
end
test "get empty motd" do
- login @user
+ login
api_get :index
assert_equal "[]", response.body, "motd response should be empty if no motd directory exists"
end
@@ -44,7 +39,7 @@ class Api::MessagesControllerTest < ApiControllerTest
=begin
setup do
InviteCodeValidator.any_instance.stubs(:validate)
- @user = FactoryGirl.build(:user)
+ @user = FactoryBot.build(:user)
@user.save
@message = Message.new(:text => 'a test message')
@message.user_ids_to_show << @user.id
diff --git a/test/functional/api/users_controller_test.rb b/test/functional/api/users_controller_test.rb
index ee183f9..dfaf959 100644
--- a/test/functional/api/users_controller_test.rb
+++ b/test/functional/api/users_controller_test.rb
@@ -96,7 +96,7 @@ class Api::UsersControllerTest < ApiControllerTest
end
test "admin can show user" do
- user = FactoryGirl.create :user
+ user = FactoryBot.create :user
login :is_admin? => true
api_get :show, :id => 0, :login => user.login, :format => :json
assert_response :success
@@ -109,7 +109,7 @@ class Api::UsersControllerTest < ApiControllerTest
end
test "admin can show is_admin property" do
- admin = FactoryGirl.create :user
+ admin = FactoryBot.create :user
with_config(admins: [admin.login]) do
login admin
api_get :show, :id => admin.id, :format => :json
diff --git a/test/functional/identities_controller_test.rb b/test/functional/identities_controller_test.rb
index 5af2e88..5e46f9c 100644
--- a/test/functional/identities_controller_test.rb
+++ b/test/functional/identities_controller_test.rb
@@ -1,4 +1,4 @@
-require_relative '../test_helper'
+require 'test_helper'
class IdentitiesControllerTest < ActionController::TestCase
@@ -26,7 +26,7 @@ class IdentitiesControllerTest < ActionController::TestCase
test "admin can unblock username" do
# an identity without user_id and destination is a blocked handle
- identity = FactoryGirl.create :identity
+ identity = create_identity
login :is_admin? => true
delete :destroy, id: identity.id
assert_response :redirect
@@ -34,13 +34,19 @@ class IdentitiesControllerTest < ActionController::TestCase
end
test "admin cannot remove main identity" do
- user = FactoryGirl.create :user
- identity = FactoryGirl.create :identity,
- Identity.attributes_from_user(user)
+ user = create_user
+ identity = create_identity Identity.attributes_from_user(user)
login :is_admin? => true
delete :destroy, id: identity.id
assert_response :redirect
assert_equal identity, Identity.find(identity.id)
end
+ def create_identity(attrs={})
+ FactoryBot.create :identity, attrs
+ end
+
+ def create_user
+ FactoryBot.create :user
+ end
end
diff --git a/test/integration/api/pgp_key_test.rb b/test/integration/api/pgp_key_test.rb
index f2744e1..1ffbe54 100644
--- a/test/integration/api/pgp_key_test.rb
+++ b/test/integration/api/pgp_key_test.rb
@@ -30,7 +30,7 @@ class PgpKeyTest < SrpTest
protected
def key
- @key ||= FactoryGirl.build :pgp_key
+ @key ||= FactoryBot.build :pgp_key
end
def assert_invalid_key_response
diff --git a/test/integration/browser/account_livecycle_test.rb b/test/integration/browser/account_livecycle_test.rb
index 68775d3..48be234 100644
--- a/test/integration/browser/account_livecycle_test.rb
+++ b/test/integration/browser/account_livecycle_test.rb
@@ -103,7 +103,7 @@ class AccountLivecycleTest < BrowserIntegrationTest
test "change pgp key" do
with_config user_actions: ['change_pgp_key'] do
- pgp_key = FactoryGirl.build :pgp_key
+ pgp_key = FactoryBot.build :pgp_key
username, _password = submit_signup
click_on "Account Settings"
within('#update_pgp_key') do
diff --git a/test/integration/browser/admin_test.rb b/test/integration/browser/admin_test.rb
index 0b43c29..ff36416 100644
--- a/test/integration/browser/admin_test.rb
+++ b/test/integration/browser/admin_test.rb
@@ -21,7 +21,7 @@ class AdminTest < BrowserIntegrationTest
end
test "clear blocked handle" do
- id = FactoryGirl.create :identity
+ id = FactoryBot.create :identity
submit_signup(id.login)
assert page.has_content?('has already been taken')
login
diff --git a/test/integration/browser/security_test.rb b/test/integration/browser/security_test.rb
index 825d50b..7073b76 100644
--- a/test/integration/browser/security_test.rb
+++ b/test/integration/browser/security_test.rb
@@ -10,7 +10,7 @@ class SecurityTest < BrowserIntegrationTest
test "detects attempt to circumvent SRP" do
InviteCodeValidator.any_instance.stubs(:validate)
- user = FactoryGirl.create :user
+ user = FactoryBot.create :user
visit '/login'
fill_in 'Username', with: user.login
fill_in 'Password', with: "password"
diff --git a/test/support/api_integration_test.rb b/test/support/api_integration_test.rb
index 7942558..94c88e1 100644
--- a/test/support/api_integration_test.rb
+++ b/test/support/api_integration_test.rb
@@ -22,7 +22,7 @@ class ApiIntegrationTest < ActionDispatch::IntegrationTest
@testcode = InviteCode.new
@testcode.save!
options.reverse_merge! invite_code: @testcode.invite_code
- FactoryGirl.create :user, options
+ FactoryBot.create :user, options
end
teardown do
diff --git a/test/support/browser_integration_test.rb b/test/support/browser_integration_test.rb
index d00e606..cff732b 100644
--- a/test/support/browser_integration_test.rb
+++ b/test/support/browser_integration_test.rb
@@ -49,7 +49,7 @@ class BrowserIntegrationTest < RackStackTest
# ApiIntegrationTest has a working implementation for RackTest
def login(user = nil)
InviteCodeValidator.any_instance.stubs(:validate)
- @user ||= user ||= FactoryGirl.create(:user)
+ @user ||= user ||= FactoryBot.create(:user)
token = Token.create user_id: user.id
page.driver.add_header "Authorization", %Q(Token token="#{token}")
visit '/'
diff --git a/test/support/stub_record_helper.rb b/test/support/stub_record_helper.rb
index 25138a0..4d74f2a 100644
--- a/test/support/stub_record_helper.rb
+++ b/test/support/stub_record_helper.rb
@@ -26,7 +26,7 @@ module StubRecordHelper
if record_or_method_hash && !record_or_method_hash.is_a?(Hash)
return record_or_method_hash
end
- FactoryGirl.build_stubbed(factory).tap do |record|
+ FactoryBot.build_stubbed(factory).tap do |record|
if persisted or record.persisted?
record_or_method_hash.reverse_merge! :created_at => Time.now,
:updated_at => Time.now, :id => Random.rand(100000).to_s
@@ -38,7 +38,7 @@ module StubRecordHelper
# returns deep stringified attributes so they can be compared to
# what the controller receives as params
def record_attributes_for(factory, attribs_hash = nil)
- FactoryGirl.attributes_for(factory, attribs_hash).tap do |attribs|
+ FactoryBot.attributes_for(factory, attribs_hash).tap do |attribs|
attribs.keys.each do |key|
val = attribs.delete(key)
attribs[key.to_s] = val.is_a?(Hash) ? val.stringify_keys! : val
diff --git a/test/unit/account_test.rb b/test/unit/account_test.rb
index ebfff6b..8923a81 100644
--- a/test/unit/account_test.rb
+++ b/test/unit/account_test.rb
@@ -58,7 +58,7 @@ class AccountTest < ActiveSupport::TestCase
test "error on invalid username" do
with_config invite_required: false do
- attributes = FactoryGirl.attributes_for :user, login: "a"
+ attributes = user_attributes login: "a"
@user = Account.create attributes
assert !@user.valid?
assert_has_errors @user, login: "Must have at least two characters"
@@ -155,7 +155,8 @@ class AccountTest < ActiveSupport::TestCase
end
test "Invite code stays zero when invite code is not used" do
- invalid_user = FactoryGirl.build(:user, :invite_code => @testcode.invite_code)
+ invalid_user = FactoryBot.build :user,
+ :invite_code => @testcode.invite_code
invalid_user.save
user_code = InviteCode.find_by_invite_code invalid_user.invite_code
user_code.save
@@ -206,7 +207,7 @@ class AccountTest < ActiveSupport::TestCase
end
def user_attributes(attrs = {})
- FactoryGirl.attributes_for :user, attrs
+ FactoryBot.attributes_for :user, attrs
end
end
diff --git a/test/unit/invite_code_validator_test.rb b/test/unit/invite_code_validator_test.rb
index 934ba2e..7c3501a 100644
--- a/test/unit/invite_code_validator_test.rb
+++ b/test/unit/invite_code_validator_test.rb
@@ -3,14 +3,14 @@ require 'test_helper'
class InviteCodeValidatorTest < ActiveSupport::TestCase
test "user should not be created with invalid invite code" do
with_config invite_required: true do
- invalid_user = FactoryGirl.build(:user)
+ invalid_user = build_user
assert !invalid_user.valid?
end
end
test "user should be created with valid invite code" do
- valid_user = FactoryGirl.build(:user)
+ valid_user = build_user
valid_code = InviteCode.create
valid_user.invite_code = valid_code.invite_code
@@ -19,7 +19,7 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase
test "trying to create a user with invalid invite code should add error" do
with_config invite_required: true do
- invalid_user = FactoryGirl.build(:user, :invite_code => "a non-existent code")
+ invalid_user = build_user :invite_code => "a non-existent code"
invalid_user.valid?
@@ -36,7 +36,7 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase
user_code.invite_count = 1
user_code.save
- user = FactoryGirl.build :user
+ user = build_user
user.invite_code = user_code.invite_code
validator.validate(user)
@@ -51,7 +51,7 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase
user_code = InviteCode.create
user_code.save
- user = FactoryGirl.build :user
+ user = build_user
user.invite_code = user_code.invite_code
validator.validate(user)
@@ -64,7 +64,7 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase
user_code = InviteCode.create
- user = FactoryGirl.build :user
+ user = build_user
user.invite_code = user_code.invite_code
validator.validate(user)
@@ -75,7 +75,7 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase
test "There is an error message if the invite code does not exist" do
validator = InviteCodeValidator.new
- user = FactoryGirl.build :user
+ user = build_user
user.invite_code = "wrongcode"
validator.validate(user)
@@ -83,4 +83,7 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase
assert_equal ["This is not a valid code"], user.errors[:invite_code]
end
+ def build_user(attrs = {})
+ FactoryBot.build :user, attrs
+ end
end
diff --git a/test/unit/token_test.rb b/test/unit/token_test.rb
index ce7edaa..3015c9a 100644
--- a/test/unit/token_test.rb
+++ b/test/unit/token_test.rb
@@ -64,7 +64,7 @@ class TokenTest < ActiveSupport::TestCase
end
test "Token.destroy_all_expired is noop if no expiry is set" do
- expired = FactoryGirl.create :token, last_seen_at: 2.hours.ago
+ expired = create_token last_seen_at: 2.hours.ago
with_config auth: {} do
Token.destroy_all_expired
end
@@ -72,8 +72,8 @@ class TokenTest < ActiveSupport::TestCase
end
test "Token.destroy_all_expired cleans up expired tokens only" do
- expired = FactoryGirl.create :token, last_seen_at: 2.hours.ago
- fresh = FactoryGirl.create :token
+ expired = create_token last_seen_at: 2.hours.ago
+ fresh = create_token
with_config auth: {token_expires_after: 60} do
Token.destroy_all_expired
end
@@ -83,7 +83,7 @@ class TokenTest < ActiveSupport::TestCase
end
test "Token.destroy_all_expired does not interfere with expired.authenticate" do
- expired = FactoryGirl.create :token, last_seen_at: 2.hours.ago
+ expired = create_token last_seen_at: 2.hours.ago
with_config auth: {token_expires_after: 60} do
Token.destroy_all_expired
end
@@ -91,7 +91,7 @@ class TokenTest < ActiveSupport::TestCase
end
test "active logout (destroy) prevents reuse" do
- token = FactoryGirl.create :token
+ token = create_token
same = Token.find(token.id)
token.destroy
assert_raises CouchRest::NotFound do
@@ -100,7 +100,7 @@ class TokenTest < ActiveSupport::TestCase
end
test "logout works on prolonged token" do
- token = FactoryGirl.create :token
+ token = create_token
same = Token.find(token.id)
token.touch
same.destroy
@@ -108,11 +108,14 @@ class TokenTest < ActiveSupport::TestCase
end
test 'second destroy carries on' do
- token = FactoryGirl.create :token
+ token = create_token
same = Token.find(token.id)
token.destroy
same.destroy
assert_nil Token.find(same.id)
end
+ def create_token(attrs = {})
+ FactoryBot.create :token, attrs
+ end
end
diff --git a/test/unit/user_test.rb b/test/unit/user_test.rb
index ab7add0..bd05170 100644
--- a/test/unit/user_test.rb
+++ b/test/unit/user_test.rb
@@ -5,7 +5,7 @@ class UserTest < ActiveSupport::TestCase
include SRP::Util
setup do
InviteCodeValidator.any_instance.stubs(:validate)
- @user = FactoryGirl.build(:user)
+ @user = FactoryBot.build(:user)
end
test "don't find a user with login nil" do
@@ -62,13 +62,13 @@ class UserTest < ActiveSupport::TestCase
end
test "login needs to be unique" do
- other_user = FactoryGirl.create :user, login: @user.login
+ other_user = FactoryBot.create :user, login: @user.login
assert !@user.valid?
other_user.destroy
end
test "login needs to be unique amongst aliases" do
- other_user = FactoryGirl.create :user
+ other_user = FactoryBot.create :user
id = Identity.create_for other_user, address: @user.login
assert !@user.valid?
id.destroy