summaryrefslogtreecommitdiff
path: root/features/step_definitions/messages_steps.rb
blob: 30bc7c3cfcf211ba24645ef86abdaf6cf0f6db51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Given /^there is a message for me$/ do
  @message = FactoryGirl.create :message, user_ids_to_show: [@user.id]
end

Given /^there is a message for me with:$/ do |options|
  attributes = options.rows_hash
  attributes.merge! user_ids_to_show: [@user.id]
  if old_message = Message.find(attributes['id'])
    old_message.destroy
  end
  @message = FactoryGirl.create :message, attributes
end

Given(/^that message is marked as read$/) do
    @message.mark_as_read_by(@user)
    @message.save
end

Then /^the response should (not)?\s?include that message$/ do |negative|
  json = JSON.parse(last_response.body)
  message = json.detect{|message| message['id'] == @message.id}
  if negative.present?
    assert !message
  else
    assert_equal @message.text, message['text']
  end
end

Then /^that message should be marked as read$/ do
  assert @message.reload.read_by? @user
  assert !@message.unread_by?(@user)
end