The personal finance app for everyone
Add initial model tests with starter fixtures for User, Family, and Account (#281)
Lee McAlilly69698d0463bf
diff --git a/test/fixtures/accounts.yml b/test/fixtures/accounts.ymlindex 2ee283d9..9f410649 100644--- a/test/fixtures/accounts.yml+++ b/test/fixtures/accounts.yml@@ -1,11 +1,14 @@-# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html+dylan_checking:+ family: dylan_family+ name: Bob's Checking+ balance: 1200-one:- family: one- name: MyString- balance:+dylan_roth:+ family: dylan_family+ name: Bob's Roth IRA+ balance: 1200-two:- family: two- name: MyString- balance:+richards_savings:+ family: richards_family+ name: Keef's HYSA+ balance: 1500\ No newline at end of filediff --git a/test/fixtures/families.yml b/test/fixtures/families.ymlindex 7d412240..a6b44dc7 100644--- a/test/fixtures/families.yml+++ b/test/fixtures/families.yml@@ -1,7 +1,7 @@# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html-one:- name: MyString+dylan_family:+ name: The Dylan Family-two:- name: MyString+richards_family:+ name: The Richards Familydiff --git a/test/fixtures/users.yml b/test/fixtures/users.ymlindex 71809897..a8cb3766 100644--- a/test/fixtures/users.yml+++ b/test/fixtures/users.yml@@ -1,15 +1,20 @@-# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html+bob:+ family: dylan_family+ first_name: Bob+ last_name: Dylan+ email: [email protected]+ password_digest: <%= BCrypt::Password.create('password') %>-one:- family: one- first_name: MyString- last_name: MyString- email: MyString- password_digest: MyString+jakob:+ family: dylan_family+ first_name: Jakob+ last_name: Dylan+ email: [email protected]+ password_digest: <%= BCrypt::Password.create('password') %>-two:- family: two- first_name: MyString- last_name: MyString- email: MyString- password_digest: MyString+keith:+ family: richards_family+ first_name: Keith+ last_name: Richards+ email: [email protected]+ password_digest: <%= BCrypt::Password.create('password') %>diff --git a/test/models/account_test.rb b/test/models/account_test.rbindex b6de6a15..8db20847 100644--- a/test/models/account_test.rb+++ b/test/models/account_test.rb@@ -1,7 +1,11 @@require "test_helper"class AccountTest < ActiveSupport::TestCase- # test "the truth" do- # assert true- # end+ test "new account should be valid" do+ depository = Account::Depository.create!+ account = Account.create!(family: families(:dylan_family), name: "Explicit Checking", balance: 1200, accountable: depository)+ assert account.valid?+ assert_not_nil account.accountable_id+ assert_not_nil account.accountable+ endenddiff --git a/test/models/family_test.rb b/test/models/family_test.rbindex 5cde4991..b9597731 100644--- a/test/models/family_test.rb+++ b/test/models/family_test.rb@@ -1,7 +1,28 @@require "test_helper"class FamilyTest < ActiveSupport::TestCase- # test "the truth" do- # assert true- # end+ def setup+ @dylan_family = families(:dylan_family)+ end++ test "should have many users" do+ assert_equal 2, @dylan_family.users.size+ assert @dylan_family.users.include?(users(:bob))+ end++ test "should have many accounts" do+ assert_equal 2, @dylan_family.accounts.size+ end++ test "should destroy dependent users" do+ assert_difference("User.count", -@dylan_family.users.count) do+ @dylan_family.destroy+ end+ end++ test "should destroy dependent accounts" do+ assert_difference("Account.count", -@dylan_family.accounts.count) do+ @dylan_family.destroy+ end+ endenddiff --git a/test/models/user_test.rb b/test/models/user_test.rbindex 5c07f490..135d7c79 100644--- a/test/models/user_test.rb+++ b/test/models/user_test.rb@@ -1,7 +1,46 @@require "test_helper"class UserTest < ActiveSupport::TestCase- # test "the truth" do- # assert true- # end+ def setup+ @user = users(:bob)+ end++ test "should be valid" do+ assert @user.valid?, @user.errors.full_messages.to_sentence+ end++ test "email must be present" do+ potential_user = User.new(+ email: "[email protected]",+ password_digest: BCrypt::Password.create("password"),+ first_name: "David",+ last_name: "Bowie"+ )+ potential_user.email = " "+ assert_not potential_user.valid?+ end++ test "has email address" do+ assert_equal "[email protected]", @user.email+ end++ test "can update email" do+ @user.update(email: "[email protected]")+ assert_equal "[email protected]", @user.email+ end++ test "email addresses must be unique" do+ duplicate_user = @user.dup+ duplicate_user.email = @user.email.upcase+ @user.save+ assert_not duplicate_user.valid?+ end++ test "email addresses are be saved as lower-case" do+ mixed_case_email = "[email protected]"+ @user.email = mixed_case_email+ @user.save+ assert_equal mixed_case_email.downcase, @user.reload.email+ endend