1
我有以下水豚測試,應該點擊並更改評論的內容。問題在於內容表單被加載到單擊編輯按鈕時彈出的模式,並且我的模式不會在測試中呈現。 (此功能在應用程序中起作用)。 save_and_open_page打開一個只包含json對象的頁面。水豚測試與AJAX響應失敗
feature_spec.rb
require 'spec_helper'
describe 'Edit comment' do
let(:commented_post) { FactoryGirl.create(:post_with_comments) }
describe "when current_user is the comment's author" do
it 'should edit the comment content' do
visit post_path(commented_post)
within ("#comment-#{commented_post.comments.first.id}") do
click_on "edit"
end
Capybara.default_wait_time = 15
save_and_open_page
fill_in 'comment_content', with: 'No, this is the best comment'
click_on 'Edit Comment'
expect(page).to have_content('No, this is the best comment')
end
end
end
post.js
var EditForm = {
init: function() {
$('.get-edit-comment').on('ajax:success', this.showEditModal);
},
showEditModal: function(e, data) {
e.preventDefault();
$('.reveal-modal').html(data.edit_template);
$('.reveal-modal').foundation('reveal', 'open');
}
}
$(document).ready(function() {
EditForm.init();
});
comments_controller.rb
def edit
@post = Post.find_by_id(params[:post_id])
@comment = Comment.find_by_id(params[:id])
render :json => {
edit_template: render_to_string(:partial => 'comments/form',
:locals => {post: @post, comment: @comment})
}
end
def update
Comment.find_by_id(params[:id]).update(comment_params)
redirect_to post_path(params[:post_id])
end