spec/keikoku/notification_spec.rb in keikokuc-0.4 vs spec/keikoku/notification_spec.rb in keikokuc-0.5

- old
+ new

@@ -6,15 +6,15 @@ fake_client = double fake_client. should_receive(:post_notification).with do |args| expect(args[:message]).to eq('hello') expect(args[:account_email]).to eq('harold@heroku.com') - end.and_return([{ id: 1 }, nil]) + end.and_return([{ :id => 1 }, nil]) - notification = build(:notification, message: 'hello', - account_email: 'harold@heroku.com', - client: fake_client) + notification = build_notification(:message => 'hello', + :account_email => 'harold@heroku.com', + :client => fake_client) result = notification.publish expect(result).to be_true expect(notification.remote_id).to eq(1) @@ -24,37 +24,38 @@ fake_client = double fake_client. should_receive(:post_notification).with do |args| expect(args[:message]).to be_nil end. - and_return([{ errors: { attributes: { message: ['is not present'] }}}, + and_return([{ :errors => { :attributes => { :message => ['is not present'] }}}, Keikokuc::Client::InvalidNotification]) - notification = build(:notification, message: nil, client: fake_client) + notification = build_notification(:message => nil, + :client => fake_client) result = notification.publish expect(result).to be_false expect(notification.remote_id).to be_nil expect(notification.errors[:attributes][:message]).to eq(['is not present']) end it 'stores attributes as instance vars' do - notification = Notification.new(message: 'foo') + notification = Notification.new(:message => 'foo') expect(notification.message).to eq('foo') end end describe Notification, '#read' do it 'marks as read to keikoku' do fake_client = double fake_client.should_receive(:read_notification). with('1234'). - and_return([{read_at: Time.now}, nil]) + and_return([{:read_at => Time.now}, nil]) - notification = Notification.new(remote_id: '1234', client: fake_client) + notification = Notification.new(:remote_id => '1234', :client => fake_client) result = notification.read expect(result).to be_true expect(notification.read_at).to be_within(1).of(Time.now) @@ -65,11 +66,12 @@ fake_client = double fake_client.stub(:read_notification). with('1234'). and_return([{}, :some_error]) - notification = Notification.new(remote_id: '1234', client: fake_client) + notification = Notification.new(:remote_id => '1234', + :client => fake_client) result = notification.read expect(result).to be_false expect(notification.read_at).to be_nil @@ -77,27 +79,27 @@ end end describe Notification, '#read?' do it 'is true if the read_at is known' do - notification = build(:notification, read_at: nil) + notification = build_notification(:read_at => nil) expect(notification.read?).to be_false notification.read_at = Time.now expect(notification.read?).to be_true end end describe Notification, '#client' do it 'defaults to a properly constructer Keikokuc::Client' do - notification = build(:notification, producer_api_key: 'fake-api-key') + notification = build_notification(:producer_api_key => 'fake-api-key') expect(notification.client).to be_kind_of(Keikokuc::Client) expect(notification.client.producer_api_key).to eq('fake-api-key') end it 'can be injected' do - notification = Notification.new(client: :foo) + notification = Notification.new(:client => :foo) expect(notification.client).to eq(:foo) end end end