Skip to content

Instantly share code, notes, and snippets.

@belguzmani
Last active October 20, 2016 16:36
Show Gist options
  • Save belguzmani/a76c45d4d11e5ff33271d4d6b39e9b03 to your computer and use it in GitHub Desktop.
Save belguzmani/a76c45d4d11e5ff33271d4d6b39e9b03 to your computer and use it in GitHub Desktop.
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
@codeprimate
Copy link

UserInvestment.completed and UserInvestment.completed_date seem to be redundant, especially considering if their values somehow become inconsistent. I would suggest making the completed attribute be a datetime and dropping the completed_date attribute. completed can be treated as “truthy”, and we can create a is_complete? getter method to return a boolean when necessary.

Nitpicks:
“Inssurance” => “Insurance” ; “Medals” => “Metals"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment