summaryrefslogtreecommitdiff
path: root/users/test/functional/v1/messages_controller_test.rb
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2014-02-10 12:44:08 +0100
committerazul <azul@riseup.net>2014-02-10 12:44:08 +0100
commitbcdde2f6bfb4ed3a1535bd2e50ab47529a9141e2 (patch)
tree6748d5170cb2a3ed387f2bf8f26bacbbc46df7d1 /users/test/functional/v1/messages_controller_test.rb
parent38474e94e3bfaeb40fb87bf2a9b8b1fbe546bc05 (diff)
parent7e0573f3347dca6323eae05127849431ecbceb77 (diff)
Merge pull request #134 from jessib/feature/messages_api
Feature/messages api
Diffstat (limited to 'users/test/functional/v1/messages_controller_test.rb')
-rw-r--r--users/test/functional/v1/messages_controller_test.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/users/test/functional/v1/messages_controller_test.rb b/users/test/functional/v1/messages_controller_test.rb
new file mode 100644
index 0000000..24a5b1f
--- /dev/null
+++ b/users/test/functional/v1/messages_controller_test.rb
@@ -0,0 +1,57 @@
+require 'test_helper'
+
+class V1::MessagesControllerTest < ActionController::TestCase
+
+ setup do
+ @user = FactoryGirl.build(:user)
+ @user.save
+ @message = Message.new(:text => 'a test message')
+ @message.user_ids_to_show << @user.id
+ @message.save
+ end
+
+ teardown do
+ @message.destroy
+ @user.destroy
+ end
+
+ test "get messages for user" do
+ login @user
+ get :index
+ assert response.body.include? @message.text
+ assert response.body.include? @message.id
+ end
+
+ test "mark message read for user" do
+ login @user
+ assert @message.user_ids_to_show.include?(@user.id)
+ assert !@message.user_ids_have_shown.include?(@user.id)
+ put :update, :id => @message.id
+ @message.reload
+ assert !@message.user_ids_to_show.include?(@user.id)
+ assert @message.user_ids_have_shown.include?(@user.id)
+ assert_json_response true
+ end
+
+ test "do not get seen messages" do
+ login @user
+ put :update, :id => @message.id
+ @message.reload
+ get :index
+ assert !(response.body.include? @message.text)
+ assert !(response.body.include? @message.id)
+ end
+
+
+ test "mark read responds even with bad inputs" do
+ login @user
+ put :update, :id => 'more nonsense'
+ assert_json_response false
+ end
+
+ test "fails if not authenticated" do
+ get :index, :format => :json
+ assert_access_denied
+ end
+
+end