Skip to content

Instantly share code, notes, and snippets.

@bhserna
Created November 11, 2016 17:58
Show Gist options
  • Select an option

  • Save bhserna/3a1de2c279276fc710981520248b8904 to your computer and use it in GitHub Desktop.

Select an option

Save bhserna/3a1de2c279276fc710981520248b8904 to your computer and use it in GitHub Desktop.
5 Rules - Tests without active record
before do
@user = user_with(first_name: "Maria")
@project_one = project_with(
fixed_annual_rate: 11,
execution_date: Date.new(2015, 10, 8),
investments: [investment_with(amount: 100_000, user: user)])
end
def project_with(attrs)
FakeProject.new({ fixed_annual_rate: 11 }.merge(attrs))
end
def investment_with(attrs)
FakeInvestment.new(attrs)
end
def user_with(attrs)
FakeUser.new(attrs)
end
class FakeInvestment
attr_reader :id, :date, :user, :amount, :user_id, :project, :project_id, :investment_type
def initialize(attrs = {})
@id = attrs[:id] || SecureRandom.uuid
@date = attrs[:date]
@user = attrs[:user]
@user_id = attrs[:user_id] || user && user.id
@amount = attrs[:amount]
@project = attrs[:project]
@project_id = attrs[:project_id] || project && project.id
@investment_type = attrs[:investment_type]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment