mirror of
https://github.com/Evolix/chexpire.git
synced 2024-05-05 02:05:09 +02:00
Test: replace fixtures with factories
This commit is contained in:
parent
611c8b78b8
commit
83df2a2ce3
|
@ -21,4 +21,12 @@
|
|||
# fk_rails_... (check_id => checks.id)
|
||||
#
|
||||
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
FactoryBot.define do
|
||||
factory :check_log do
|
||||
check
|
||||
status :pending
|
||||
exit_status nil
|
||||
parsed_response nil
|
||||
raw_response nil
|
||||
end
|
||||
end
|
|
@ -26,30 +26,28 @@
|
|||
# fk_rails_... (user_id => users.id)
|
||||
#
|
||||
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
FactoryBot.define do
|
||||
factory :check do
|
||||
user
|
||||
kind :domain
|
||||
domain "domain.fr"
|
||||
domain_created_at Time.new(2016, 4, 1, 12, 0, 0, "+02:00")
|
||||
domain_updated_at Time.new(2017, 3, 1, 12, 0, 0, "+02:00")
|
||||
domain_expire_at Time.new(2019, 4, 1, 12, 0, 0, "+02:00")
|
||||
active true
|
||||
vendor nil
|
||||
comment nil
|
||||
last_run_at nil
|
||||
last_success_at nil
|
||||
|
||||
domain_example_org:
|
||||
user: user1
|
||||
kind: domain
|
||||
domain: example.org
|
||||
domain_created_at: 2017-03-01 17:29:50
|
||||
domain_updated_at: 2018-02-15 12:10:00
|
||||
domain_expire_at: 2019-03-01 17:29:49
|
||||
last_run_at: 2018-05-24 17:29:50
|
||||
last_success_at: 2018-05-24 17:29:50
|
||||
vendor: ""
|
||||
comment: ""
|
||||
active: true
|
||||
trait :domain do
|
||||
kind :domain
|
||||
end
|
||||
|
||||
ssl_www_example_org:
|
||||
user: user1
|
||||
kind: ssl
|
||||
domain: www.example.org
|
||||
domain_created_at: 2018-05-24 17:29:50
|
||||
domain_updated_at: 2018-05-24 17:29:50
|
||||
domain_expire_at: 2019-05-24 17:29:49
|
||||
last_run_at: 2018-05-24 17:29:50
|
||||
last_success_at: 2018-05-24 17:29:50
|
||||
vendor: ""
|
||||
comment: "MyString"
|
||||
active: true
|
||||
trait :nil_dates do
|
||||
domain_created_at nil
|
||||
domain_updated_at nil
|
||||
domain_expire_at nil
|
||||
end
|
||||
end
|
||||
end
|
|
@ -21,20 +21,29 @@
|
|||
# fk_rails_... (check_id => checks.id)
|
||||
#
|
||||
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
FactoryBot.define do
|
||||
factory :notification do
|
||||
check
|
||||
delay 30
|
||||
channel :email
|
||||
recipient "recipient@domain.fr"
|
||||
status :pending
|
||||
sent_at nil
|
||||
|
||||
one:
|
||||
check: domain_example_org
|
||||
channel: email
|
||||
recipient: myemail@example.org
|
||||
delay: 30
|
||||
sent_at: 2018-05-31 10:14:12
|
||||
status: succeed
|
||||
trait :email do
|
||||
channel :email
|
||||
end
|
||||
|
||||
two:
|
||||
check: domain_example_org
|
||||
channel: email
|
||||
recipient: myemail@example.org
|
||||
delay: 10
|
||||
sent_at: 2018-05-31 10:14:12
|
||||
status: succeed
|
||||
trait :ongoing do
|
||||
status :ongoing
|
||||
end
|
||||
|
||||
trait :succeed do
|
||||
status :succeed
|
||||
end
|
||||
|
||||
trait :failed do
|
||||
status :failed
|
||||
end
|
||||
end
|
||||
end
|
|
@ -28,15 +28,14 @@
|
|||
# index_users_on_email (email) UNIQUE
|
||||
# index_users_on_reset_password_token (reset_password_token) UNIQUE
|
||||
#
|
||||
require "securerandom"
|
||||
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
# This model initially had no columns defined. If you add columns to the
|
||||
# model remove the '{}' from the fixture names and add the columns immediately
|
||||
# below each fixture, per the syntax in the comments below
|
||||
#
|
||||
user1:
|
||||
email: user@chexpire.org
|
||||
encrypted_password: <%= User.new.send(:password_digest, 'password') %>
|
||||
confirmed_at: <%= 1.minute.ago %>
|
||||
tos_accepted: true
|
||||
FactoryBot.define do
|
||||
factory :user do
|
||||
email { "user-#{SecureRandom.random_number}@chexpire.org" }
|
||||
password "password"
|
||||
confirmed_at Time.new(2018, 4, 1, 12, 0, 0, "+02:00")
|
||||
notifications_enabled true
|
||||
tos_accepted true
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@ require "system_command"
|
|||
|
||||
class CheckLoggerTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@check = checks(:domain_example_org)
|
||||
@check = create(:check)
|
||||
@logger = CheckLogger.new(@check)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
require "application_system_test_case"
|
||||
|
||||
class UsersTest < ApplicationSystemTestCase
|
||||
setup do
|
||||
@user = create(:user)
|
||||
end
|
||||
|
||||
test "an user can signup from the homepage and confirm its account" do
|
||||
visit root_path
|
||||
|
||||
|
@ -31,28 +35,25 @@ class UsersTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
test "an user can signin from the homepage" do
|
||||
user = users(:user1)
|
||||
visit root_path
|
||||
|
||||
click_on I18n.t("shared.navbar.sign_in")
|
||||
|
||||
fill_in "user[email]", with: user.email
|
||||
fill_in "user[email]", with: @user.email
|
||||
fill_in "user[password]", with: "password"
|
||||
|
||||
click_button I18n.t("devise.sessions.new.sign_in")
|
||||
|
||||
assert_equal root_path, page.current_path
|
||||
assert page.has_content?(user.email)
|
||||
assert page.has_content?(@user.email)
|
||||
end
|
||||
|
||||
test "an user can signout from the homepage" do
|
||||
user = users(:user1)
|
||||
|
||||
login_as user
|
||||
login_as @user
|
||||
visit root_path
|
||||
|
||||
find ".navbar" do
|
||||
click_on user.email
|
||||
click_on @user.email
|
||||
click_on I18n.t("shared.navbar.sign_out")
|
||||
end
|
||||
|
||||
|
@ -90,12 +91,11 @@ class UsersTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
test "an user can globally disable its notifications" do
|
||||
user = users(:user1)
|
||||
login_as user
|
||||
login_as @user
|
||||
|
||||
visit edit_user_registration_path
|
||||
|
||||
assert_equal user.email, find_field("user[email]").value
|
||||
assert_equal @user.email, find_field("user[email]").value
|
||||
|
||||
assert find_field("user[notifications_enabled]").value
|
||||
uncheck "user[notifications_enabled]"
|
||||
|
@ -104,7 +104,7 @@ class UsersTest < ApplicationSystemTestCase
|
|||
|
||||
click_button I18n.t("devise.registrations.edit.update")
|
||||
|
||||
user.reload
|
||||
refute user.notifications_enabled
|
||||
@user.reload
|
||||
refute @user.notifications_enabled
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue