Skip to content

Instantly share code, notes, and snippets.

@perezpaya
Created March 29, 2016 04:18
Show Gist options
  • Save perezpaya/728bc9b7f41450cf14d2 to your computer and use it in GitHub Desktop.
Save perezpaya/728bc9b7f41450cf14d2 to your computer and use it in GitHub Desktop.
describe CompanyMarketUpdatesService, type: :service do
let(:notification_job) { object_spy(NotificationJob) }
let(:service) { described_class.new(notification_job: notification_job)
let(:apple) { Company.create!(name: 'Apple', stock_symbol: 'APPL', stock_volume: 22000000, stock_price: 100.0, number_of_shares: 100000000) }
it 'modifies company stockage information' do
updated_company = service.update(stock_symbol: apple.stock_symbol, stock_volume: 23000000, stock_price: 105.0)
expect(updated_company.stock_price).to eq(105.0)
expect(updated_company.stock_volume).to eq(23000000)
end
it 'sends a notification when the stock price goes down' do
expect(notification_job).to receive(:perform_later).with(hash_including(:message => kind_of(String))).and_return(kind_of(Company))
service.update(stock_symbol: apple.stock_symbol, stock_volume: 24000000, stock_price: 80.0)
end
it 'does not send a notification when the stock price goes up' do
service.update(stock_symbol: apple.stock_symbol, stock_volume: 25000000, stock_price: 200.0)
expect(notification_job).not_to have_received(:perform_later).with(hash_including(:message => kind_of(String)))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment