From 150c80bfc7c469b23f7ac1bac0e42014ad417df6 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 14 Jul 2014 17:26:28 +0200 Subject: add translation and fix tests --- config/locales/errors.en.yml | 1 + config/locales/messages.en.yml | 4 ++++ test/functional/v1/messages_controller_test.rb | 4 ++-- test/support/assert_responses.rb | 19 +++++++++++++++++-- 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 config/locales/messages.en.yml diff --git a/config/locales/errors.en.yml b/config/locales/errors.en.yml index 93feab1..e0a909f 100644 --- a/config/locales/errors.en.yml +++ b/config/locales/errors.en.yml @@ -9,3 +9,4 @@ en: text: not_found: "You may have mistyped the address or the page may have moved." server_error: The problem has been logged and we will look into it. + not_found: Not found. diff --git a/config/locales/messages.en.yml b/config/locales/messages.en.yml new file mode 100644 index 0000000..d9d7613 --- /dev/null +++ b/config/locales/messages.en.yml @@ -0,0 +1,4 @@ +en: + messages: + not_found: That message could not be found. + marked_as_read: Message has been marked as read. diff --git a/test/functional/v1/messages_controller_test.rb b/test/functional/v1/messages_controller_test.rb index a50fded..6f7ea5d 100644 --- a/test/functional/v1/messages_controller_test.rb +++ b/test/functional/v1/messages_controller_test.rb @@ -30,7 +30,7 @@ class V1::MessagesControllerTest < ActionController::TestCase @message.reload assert !@message.user_ids_to_show.include?(@user.id) assert @message.user_ids_have_shown.include?(@user.id) - assert_json_response true + assert_success :marked_as_read end test "do not get seen messages" do @@ -46,7 +46,7 @@ class V1::MessagesControllerTest < ActionController::TestCase test "mark read responds even with bad inputs" do login @user put :update, :id => 'more nonsense' - assert_json_response false + assert_not_found end test "fails if not authenticated" do diff --git a/test/support/assert_responses.rb b/test/support/assert_responses.rb index 1c9d49d..7724fb4 100644 --- a/test/support/assert_responses.rb +++ b/test/support/assert_responses.rb @@ -20,6 +20,22 @@ module AssertResponses response end + def response_content + json_response || get_response.body + end + + def assert_success(message) + assert_response :success + assert_response_includes :success + assert_equal message.to_s, json_response[:success] if message.present? + end + + def assert_not_found + assert_response :not_found + assert_response_includes :error + assert_equal 'not_found', json_response[:error] + end + def assert_text_response(body = nil) assert_equal 'text/plain', content_type unless body.nil? @@ -45,8 +61,7 @@ module AssertResponses # checks for the presence of a key in a json response # or a string in a text response def assert_response_includes(string_or_key) - response = json_response || get_response.body - assert response.include?(string_or_key), + assert response_content.include?(string_or_key), "response should have included #{string_or_key}" end -- cgit v1.2.3