Last active
October 20, 2016 16:36
-
-
Save belguzmani/a76c45d4d11e5ff33271d4d6b39e9b03 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe InvestmentType, type: :model do | |
subject { create :investment_type } | |
it { is_expected.to have_attributes(name: 'Real Estate') } | |
end | |
RSpec.describe ComplianceItems, type: :model do | |
context 'no parents' do | |
subject { create :compliance_item } | |
it { should belong_to(:investment_type) } # Real Estate | |
it { is_expected.to have_attributes(title: 'Insurance in place ?') } | |
it { is_expected.to have_attributes(parents: []) } | |
end | |
context 'with parents' do | |
let(:insurance) { create :compliance_item, title: 'Insurance in place ?' } # id: 1 | |
let(:valuation) { create :compliance_item, title: 'Valuation complete ?' } # id: 2 | |
subject { create :compliance_item, title: '5500 filed ?', parents: [insurance.id, valuation.id] } | |
it { should belong_to(:investment_type) } # Real Estate | |
it { is_expected.to have_attributes(title: '5500 filed ?') } | |
it { is_expected.to have_attributes(parent_ids: [1, 2]) } | |
end | |
end | |
RSpec.describe UserInvestments, type: :model do | |
context 'Real Estate' do | |
subject { create :user_investment } # Real Estate | |
it { should belong_to(:investment_type) } | |
it { should belong_to(:user) } | |
it { should have_many(:user_compliances) } | |
it { is_expected.to have_attributes(title: 'X Propoerty') } | |
end | |
context 'Precious Metals' do | |
let(:metals) { create :investment_type, name: 'Precious Metals'} | |
subject { create :user_investments, investment_type: metals } | |
it { should belong_to(:investment_type) } | |
it { should belong_to(:user) } | |
it { should have_many(:user_compliances) } | |
it { is_expected.to have_attributes(title: 'Gold Bars') } | |
end | |
end | |
RSpecs.describe UserCompliance, type: :model do | |
context 'Insurance in place? COMPLETED' do | |
let(:uinv) { create :user_investment } # Real estate - X Property | |
subject { create :user_compliance, user_investment: uinv, completed: true } | |
it { should belong_to(:user_investment) } | |
it { should belong_to(:compliance_item) } | |
it { is_expected.to have_attributes(compliance_item.title: 'Insurance in place ?' } } | |
it { is_expected.to have_attributes(due_date: Date.today + 15.days ) } | |
it { is_expected.to have_attributes(completed: Date.today) } | |
end | |
context '5500 filed? PENDING' do | |
let(:uinv) { create :user_investment } # Real Estate - X Property | |
let(:citem) { create :compliance_item, title: '5500 filed ?' } | |
subject { create :user_compliance, user_investment: uinv, compliance_item: citem } | |
it { should belong_to(:user_investment) } | |
it { should belong_to(:compliance_item) } | |
it { is_expected.to have_attributes(compliance_item.title: '5500 filed ?' } } | |
it { is_expected.to have_attributes(due_date: Date.today + 15.days ) } | |
it { is_expected.to have_attributes(completed: nil) } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
UserInvestment.completed
andUserInvestment.completed_date
seem to be redundant, especially considering if their values somehow become inconsistent. I would suggest making thecompleted
attribute be adatetime
and dropping thecompleted_date
attribute.completed
can be treated as “truthy”, and we can create ais_complete?
getter method to return a boolean when necessary.Nitpicks:
“Inssurance” => “Insurance” ; “Medals” => “Metals"