Created
February 3, 2017 03:04
-
-
Save somethvictory/a3c9cf0942352812ff0692b95b6d84cf to your computer and use it in GitHub Desktop.
Organise your spec by grouping under its own functionality.
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
require 'rails_helper' | |
describe Charge, 'validations', type: :model do | |
it { is_expected.to validate_presence_of(:amount) } | |
it { is_expected.to validate_presence_of(:customer) } | |
end | |
describe Charge, 'delegations', type: :model do | |
it { is_expected.to delegate_method(:name).to(:customer).with_prefix(true) } | |
end | |
describe Charge, 'associations', type: :model do | |
it { is_expected.to belong_to(:customer) } | |
end | |
describe Charge, 'Scope', type: :model do | |
it 'returns all paid charges', '.successful' do | |
expect(Charge.successful.count).to eq 10 | |
expect(Charge.successful.pluck(:paid).uniq).to eq [true] | |
expect(Charge.successful.pluck(:refunded).uniq).to eq [false] | |
end | |
it 'returns all failed charges', '.failed' do | |
expect(Charge.failed.count).to eq 5 | |
expect(Charge.failed.pluck(:paid).uniq).to eq [false] | |
expect(Charge.failed.pluck(:refunded).uniq).to eq [false] | |
end | |
it 'returns all disputed charges', '.disputed' do | |
expect(Charge.disputed.count).to eq 5 | |
expect(Charge.disputed.pluck(:paid).uniq).to eq [true] | |
expect(Charge.disputed.pluck(:refunded).uniq).to eq [true] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment