summaryrefslogtreecommitdiff
path: root/features/step_definitions
diff options
context:
space:
mode:
authorazul <azul@leap.se>2014-07-18 12:21:49 +0200
committerazul <azul@leap.se>2014-07-18 12:21:49 +0200
commitbbd41c9bfd2cb88a88d7436dd58a8b46a5d10cf1 (patch)
tree00b39da219151473437c02ce35344117bcd5b2fa /features/step_definitions
parentade74d8a9091ae607586d7b287a0579a2ee7af8e (diff)
parent20352249fa5dafe3abb2d4b751b1e5c8c0a59abc (diff)
Merge pull request #180 from azul/feature/messages-api
Feature/messages api
Diffstat (limited to 'features/step_definitions')
-rw-r--r--features/step_definitions/api_steps.rb8
-rw-r--r--features/step_definitions/messages_steps.rb32
2 files changed, 36 insertions, 4 deletions
diff --git a/features/step_definitions/api_steps.rb b/features/step_definitions/api_steps.rb
index a4f369c..7188694 100644
--- a/features/step_definitions/api_steps.rb
+++ b/features/step_definitions/api_steps.rb
@@ -13,8 +13,9 @@ end
Given /^I set headers:$/ do |headers|
headers.rows_hash.each do |key,value|
- value.sub!('MY_AUTH_TOKEN', @my_auth_token.to_s) if @my_auth_token
- header key, value
+ replace = value.dup
+ replace.sub!('MY_AUTH_TOKEN', @my_auth_token.to_s) if @my_auth_token
+ header key, replace
end
end
@@ -36,7 +37,7 @@ When /^I digest\-authenticate as the user "(.*?)" with the password "(.*?)"$/ do
digest_authorize user, pass
end
-When /^I send a (GET|POST|PUT|DELETE) request (?:for|to) "([^"]*)"(?: with the following:)?$/ do |*args|
+When /^I (?:have sent|send) a (GET|POST|PUT|DELETE) request (?:for|to) "([^"]*)"(?: with the following:)?$/ do |*args|
request_type = args.shift
path = args.shift
input = args.shift
@@ -50,7 +51,6 @@ When /^I send a (GET|POST|PUT|DELETE) request (?:for|to) "([^"]*)"(?: with the f
request_opts[:input] = input
end
end
-
request path, request_opts
end
diff --git a/features/step_definitions/messages_steps.rb b/features/step_definitions/messages_steps.rb
new file mode 100644
index 0000000..30bc7c3
--- /dev/null
+++ b/features/step_definitions/messages_steps.rb
@@ -0,0 +1,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