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