2011-09-20 96 views
4

如何模擬rspec請求規範中的拖放功能?在rails 3中測試拖放功能

我有#divItem元素我在#divContainer元素(jquery)中拖放。在頁面刷新時,我想確保#divItem元素在#divContainer元素中。

回答

7
it "should drag item to new list", :js => true do 
    item = Item.create!(:title => "title 1", :group => "group 1") 

    # verify that item is withing group 1 
    visit items_path 
    within("#group 1") do # id of a div element (or ul element) 
    page.should have_content("title 1") 
    end  

    item_element = find("##{item.id}")  
    new_group_element = find("#group 2") 
    item_element.drag_to new_group_element 

    # verify that after page reload item is withing the new group 
    visit items_path 
    within("#group 2") do 
    page.should have_content("title 1") 
    end 

end