Functional testing :update action of JSON API in Rails 4 -
i've been struggling long time, trying knows how many combinations - no avail. seems several others on , google haven't been able resolve this.
essentially, i'm posting :update action on controller within rails 4's built-in functional testing framework. app strictly json api, need post :update request json request. works beautifully in wild, functional test syntax can't seem grasp of need.
here's current attempt:
test "should able update location" post :update, id: 1, format: :json, '{"is_private": "false"}' :show, id: 1, format: :json assert_equal json['data'][0]['is_private'], false end
running rake test results in syntax error:
unexpected '\n', expecting =>
for clarity's sake, controller action looks this:
def update @location = location.find(params[:id]) if @location.update_attributes(activesupport::json.decode(request.body.read)) api_response(@location) else respond_with api_error end end
what missing here? possible test json posts rails 4's built-in functional testing framework? official documentation quite terse on issue.
rubber duck programming work. i've got sorted out:
test "should able update location" update = { is_private: false }.to_json patch(:update, update, id: 1) :show, id: 1, format: :json assert_equal json['data'][0]['is_private'], false end
ruby-on-rails ruby-on-rails-4 functional-testing json-api
No comments:
Post a Comment