ruby on rails - bad URI(is not URI?) while testing | Rspec -
i`ve got these strange issues dont know how fix it. please me if can.
here testing result:
1) admin can edit hotel failure/error: visit edit_admin_hotel_path(hotel) uri::invalidurierror: bad uri(is not uri?): # ./spec/requests/admin_spec.rb:32:in `block (2 levels) in <top (required)>' 2) admin can edit user failure/error: visit edit_admin_user_path(admin) uri::invalidurierror: bad uri(is not uri?): # ./spec/requests/admin_spec.rb:54:in `block (2 levels) in <top (required)>'
rake routes
shows me nice edit routes users , hotels:
edit_admin_hotel /admin/hotels/:id/edit(.:format) admin/hotels#edit edit_admin_user /admin/users/:id/edit(.:format) admin/users#edit
and works fine if start server , check manually. have no idea these issues comes from. help! , admin_spec.rb file:
require 'spec_helper' describe "admin" let(:admin) { factorygirl.create(:user) } let(:hotel) { factorygirl.create(:hotel) } before(:each) sign_up_as_admin admin visit admin_hotels_path end subject { page } { expect(page).to have_content("manage hotels") } { expect(page).to have_content("manage users") } { expect(page).to have_link("sign out") } { expect(page).to have_content("list of hotels") } { expect(page).to have_content("hello, admin") } "can add hotel" click_link "add hotel" expect(current_path).to eq(new_admin_hotel_path) fill_in 'name', with: "testhotel" fill_in 'price', with: "666" fill_in 'star_rating', with: "5" expect { click_button "submit" }.to change(hotel,:count).by(1) expect(current_path).to eq(admin_hotel_path(1)) end "can edit hotel" visit edit_admin_hotel_path(hotel) end "can delete hotel" visit admin_hotel_path(hotel) expect { click_link "delete hotel" }.to change(hotel,:count).by(-1) #expect { click_link "delete hotel" }.to redirect_to(admin_hotels_path) end "can create new user" click_link "add user" expect(current_path).to eq(new_admin_user_path) expect(page).to have_content("create new user") fill_in "name", :with => "user" fill_in "email", :with => "user@auser.com" fill_in "password", :with => "user.password" fill_in "password_confirmation", :with => "user.password" expect { click_button "create user" }.to change(user,:count).by(1) expect(current_path).to eq(admin_users_path) end "can edit user" visit edit_admin_user_path(admin) end end
edit/update actions in users_controller.rb:
# admin/users/1/edit def edit @user = user.find(params[:id]) render "edit", status: 302 end # patch/put admin/users/1 def update @user = user.find(params[:id]) if @user.try(:update_attributes, user_params) render "edit", notice: 'user updated.' else render action: 'edit' end end private def user_params params.require(:user).permit(:name, :email, :password, :password_confirmation, :admin) end
and user/edit.html.erb:
<% provide(:title, "edit user") %> <h1>update profile</h1> <div class="row"> <div class="span6 offset3"> <%= form_for([:admin, @user]) |f| %> <%= render 'shared/error_messages', object: f.object %> <%= f.label :name %> <%= f.text_field :name %> <%= f.label :email %> <%= f.text_field :email %> <%= f.label :password %> <%= f.password_field :password %> <%= f.label :password_confirmation, "confirm password" %> <%= f.password_field :password_confirmation %> <%= f.submit "save changes" %> <% end %> <%= button_to 'delete user', [:admin, @user], :data => { confirm: 'are sure?' }, method: :delete %> </div> </div>
update 1: found out these bad uri(is not uri?)
errors in hotel_controller , comment_controller while testing edit action. these errors in of controllers in edit actions , dont know cousing them :(
your edit action wrong:
def edit @user = user.find(params[:id]) render "edit", status: 302 end
a 302 status means response redirect , location
header in response contains uri (relative or absolute) redirect to. capybara looking header , winds trying uri.parse(nil)
.
it's not clear me why setting status here @ all
Comments
Post a Comment