Created
October 31, 2012 18:30
-
-
Save joshsmith/3988915 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'spec_helper' | |
| feature 'Add artwork' do | |
| before do | |
| @user = create(:user) | |
| login(@user) | |
| @image_path = Rails.root + "spec/fixtures/brooklyn.jpeg" | |
| @files = [ @image_path ] | |
| end | |
| scenario "Successful artwork add by dropping file", :js => true do | |
| click_link "quick-add-art-link" | |
| page.should have_content("Add new Artwork") | |
| drop_files @files, '.art-dropzone' # dropping anywhere on the document works | |
| page.should have_content("You chose: brooklyn.jpeg") | |
| wait_until { find("#preview-image").visible? } | |
| fill_in "artwork_title", :with => "Test Artwork" | |
| fill_in "artwork_description", :with => "Here's a nice test description." | |
| click_button "Save Your Art" | |
| page.should have_content("Wow, nice work. You added some awesome art!") | |
| page.should have_content("Test Artwork") | |
| page.should have_content("Here's a nice test description.") | |
| end | |
| scenario "Successful artwork add by clicking choose file", :js => true do | |
| click_link "quick-add-art-link" | |
| page.should have_content("Add new Artwork") | |
| attach_file "artwork_image", @image_path | |
| wait_until { find("#preview-image").visible? } | |
| fill_in "artwork_title", :with => "Test Artwork" | |
| fill_in "artwork_description", :with => "Here's a nice test description." | |
| click_button "Save Your Art" | |
| page.should have_content("Wow, nice work. You added some awesome art!") | |
| page.should have_content("Test Artwork") | |
| page.should have_content("Here's a nice test description.") | |
| end | |
| scenario "Failed artwork add" do | |
| click_link "quick-add-art-link" | |
| click_button "Save Your Art" | |
| page.should have_content("Title can't be blank") | |
| page.should have_content("Image can't be blank") | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def drop_files files, drop_area | |
| js_script = "fileList = Array();" | |
| files.count.times do |i| | |
| # Generate a fake input selector | |
| page.execute_script("if ($('#seleniumUpload#{i}').length == 0) { seleniumUpload#{i} = window.$('<input/>').attr({id: 'seleniumUpload#{i}', type:'file'}).appendTo('body'); }") | |
| # Attach file to the fake input selector through Capybara | |
| attach_file("seleniumUpload#{i}", files[i]) | |
| # Build up the fake js event | |
| js_script = "#{js_script} fileList.push(seleniumUpload#{i}.get(0).files[0]);" | |
| end | |
| # Trigger the fake drop event | |
| page.execute_script("#{js_script} e = $.Event('drop'); e.originalEvent = {dataTransfer : { files : fileList } }; $('#{drop_area}').trigger(e);") | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment