2013-07-13 4 views
0

У меня есть некоторые проблемы с моим тестом.ActionController :: RoutingError: нет совпадений маршрута [PUT] rspec

Существует мой profile_pages_spec.rb:

describe "ProfilePages" do 

subject { page } 

describe "edit" do 
    let(:user) { FactoryGirl.create(:user) } 
    let(:profile) do 
    FactoryGirl.create(:profile, user: user) 
    end 
before do 
    login user 
    visit edit_profile_path(profile) 
end 

it { should have_selector('h2', text: 'Заполните информацию о себе') } 

describe "change information" do 
    let(:new_city) { "Ulan-Bator" } 
    let(:new_phone) { 1232442 } 
    let(:new_gamelevel) { "M2" } 
    let(:new_aboutme) { "nfsfsdfds" } 
    let(:submit) { "Сохранить" } 
    before do 
    fill_in "Город",    with: new_city 
    fill_in "Телефон",   with: new_phone 
    select new_gamelevel,  from: "Уровень игры" 
    fill_in "О себе",   with: new_aboutme 
    click_button submit 
    end 
    specify { profile.reload.city.should == new_city } 
    specify { profile.reload.phone.should == new_phone } 
    specify { profile.reload.gamelevel.should == new_gamelevel } 
    specify { profile.reload.aboutme.should == new_aboutme } 
end 
describe "submitting to the update action" do 
    before { put edit_profile_path(profile) } 
    specify { response.should redirect_to(user_path(user)) } 
end 
end 
end 

Существует мой profiles_controller.rb:

def edit 
    @profile = current_user.profile 
    end 

    def update 
    @profile = current_user.profile 
    if @profile.update_attributes(params[:profile]) 
    flash[:success] = "Профиль обновлен!" 
    redirect_to user_path(current_user) 
    else 
    render 'edit' 
    end 
end 

Форма профиля:

 <%= form_for(@profile) do |f| %> 

    <%= render 'devise/shared/error_messages', object: f.object %> 

     <div><%= f.label :city, "Город" %> 
     <%= f.text_field :city, :autofocus => true %></div> 

     <div><%= f.label :phone, "Телефон" %> 
     <%= f.number_field :phone %></div> 

     <div><%= f.label :gamelevel, "Уровень игры" %> 
     <%= f.select(:gamelevel,[['Pro', 'Pro'], 
           ['M1', 'M1'], 
           ['M2', 'M2'], 
           ['M3', 'M3']]) %></div> 

     <div><%= f.label :aboutme,"О себе" %> 

     <%= f.text_area :aboutme, placeholder: "Немного о себе...",size: "    40x10"  %></div> 

     <div><%= f.submit "Сохранить", class: "btn btn-primary" %></div> 
    <% end %> 

В светлячок я могу s моя форма и данные будут меняться. Но в моей спецификации у меня есть ошибка:

ActionController :: RoutingError: нет маршрута матчей [PUT]

рек маршрутов:

edit_profile GET /profiles/:id/edit(.:format) профилями # редактировать

профиль PUT /profiles/:id(.:format) профили # обновить

Я не понимаю, что я сделал неправильно.

ответ

0

Проблема заключается в том, что запрос PUT HTTP должен выполняться по пути profile_path, а не по пути edit_profile_, как вы это делали. Путь edit_profile_path работает с запросом GET и отображает форму профиля редактирования. Это на самом деле не обновлять профиль ...

Попробуйте

before { put profile_path(profile) } 
+0

работы это. Но другая ошибка: Ошибка/Ошибка: укажите {response.should redirect_to (user_path (пользователь))} Ожидаемый ответ будет перенаправлен на , но был перенаправлен на < http://www.example.com/users/sign_in> Я думаю, что это что-то не так с помощью помощников. –

Смежные вопросы