Does your controller support both HTML and JSON responses?

Based on your snippets you aren't setting the Accept header in the request.
If a default format isn't set in the routes then Rails will assume HTML. If
the controller then checks the format it will use the HTML response path.

On Dec 29, 2016 1:19 PM, <[email protected]> wrote:

> Hello i have two controllers :
>
> CalendarsController and EventsController
>
> I'm writing a request spec where i try to create an event but before that
> i should create a Calendar to get an id.
>
> So i do in my requests specs :
>
> RSpec.describe "Event Management", :type => request do
>
> context "with access token" do
>   it "creates a calendar"
>     post calendars_create_path, params: {name: "test"}
>     expect(response.status).to eq(201)
>   end
> end
>
> and in the create method of calendars controller i do :
>
> render json: @data, status: response.status
>
> When i test the same test from above in the Calendars Controller spec it
> works fine and i get the right status code (201)
>
> But in the requests specs it sends back a 307 http redirect code (it
> triest to redirect to GET /calendars/create) for some reasons even tho i
> have this in routes.rb :
>
>           calendars_index GET      /calendars/index(.:format)
> calendars#index
>             calendars_new GET      /calendars/new(.:format)
> calendars#new
>          calendars_create POST     /calendars/create(.:format)
>  calendars#create
>          calendars_update PATCH    /calendars/update(.:format)
>  calendars#update
>         calendars_destroy DELETE   /calendars/destroy(.:format)
> calendars#destroy
>            calendars_show GET      /calendars/show(.:format)
>  calendars#show
>            calendars_edit GET      /calendars/edit(.:format)
>  calendars#edit
>          calendars_delete GET      /calendars/delete(.:format)
>  calendars#delete
>
> so i don't understand why its trying to redirect. Any ideas ?
>
> Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/rspec/de2b037e-3f70-4989-8cbf-47171e2af697%40googlegroups.com
> <https://groups.google.com/d/msgid/rspec/de2b037e-3f70-4989-8cbf-47171e2af697%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/CAKCESdiER0x-%3DUoSxuXyYnZD2YTpQB7j1auoxHzn9tdrBa342g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to