forked from radiant/radiant-page-attachments-extension
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use nested attributes to save, reorder attachments. Test with cucumbe…
…r + webrat + selenium
- Loading branch information
Showing
26 changed files
with
284 additions
and
139 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
%li{:id => "attachment_#{attachment.id}", :class =>"attachment clearfix"} | ||
= hidden_field_tag "page[attachments_attributes][#{attachment_counter}][id]", attachment.id | ||
= hidden_field_tag "page[attachments_attributes][#{attachment_counter}][_delete]", "0" | ||
= hidden_field_tag "page[attachments_attributes][#{attachment_counter}][position]", attachment.position | ||
- unless attachment.first? && attachment.last? | ||
= image_tag 'admin/drag_order.png', :alt => "Drag handle", :title => "Drag to change order", :class => 'drag-order' | ||
%div= image_tag "admin/minus.png", :alt => "Delete", :class => 'delete' | ||
- unless attachment.thumbnails.empty? | ||
= link_to image_tag(attachment.public_filename("icon")), attachment.public_filename, :class => 'thumbnail' | ||
- unless attachment.title.blank? | ||
%p= h attachment.short_title | ||
= link_to attachment.short_filename, attachment.public_filename |
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#attachments | ||
.toolbar | ||
= image_tag('admin/plus.png', :alt => 'Add') | ||
= hidden_field_tag('attachment_index', @page.attachments.size, :id => 'attachment-index-field') | ||
%h3 | ||
Attachments ( | ||
%span#attachment_count>= @page.attachments.count | ||
) | ||
- unless @page.attachments.count.zero? | ||
%ol#attachment_list | ||
= render :partial => 'attachment', :collection => @page.attachments | ||
%div{:style => "clear:both;"} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Feature: attachments | ||
As a content editor | ||
I should be able to add, reorder, and delete attachments | ||
|
||
Background: | ||
Given I am logged in as admin | ||
|
||
Scenario: attach a file | ||
Given I have a page with no attachments | ||
When I edit the page | ||
And I click the plus icon | ||
And I attach the Rails logo | ||
And I save | ||
Then the page should have a new attachment | ||
|
||
Scenario: don't change attachments | ||
Given I have a page with 2 attachments | ||
When I edit the page | ||
And I save | ||
Then the page should have 2 attachments | ||
|
||
Scenario: attach another file | ||
Given I have a page with 2 attachments | ||
When I edit the page | ||
And I click the plus icon | ||
And I attach the Rails logo | ||
And I save | ||
Then the page should have 3 attachments | ||
|
||
Scenario: delete a file | ||
Given I have a page with 2 attachments | ||
When I edit the page | ||
And I delete the first attachment | ||
And I save | ||
Then the page should have 1 attachment | ||
|
||
Scenario: reorder attachments | ||
Given I have a page with 2 attachments | ||
When I edit the page | ||
And I drag attachment 2 above attachment 1 | ||
And I save | ||
Then attachment 2 should be in position 1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require File.expand_path(File.join(File.dirname(__FILE__), "..", "support", "paths")) | ||
|
||
Given /^I am logged in as (.*)(?: user)?$/ do |username| | ||
visit login_path | ||
fill_in "Username", :with => username | ||
fill_in "Password", :with => "password" | ||
click_button "Login" | ||
end | ||
|
||
Given /^I have a page$/ do | ||
@page = pages(:home) | ||
end | ||
|
||
Given /^I have a page with (\d+) attachments$/ do |number| | ||
Given "I have a page" | ||
@page.attachments.length.should == number.to_i | ||
end | ||
|
||
Given /^I have a page with no attachments$/ do | ||
@page = pages(:first) | ||
@page.attachments.should be_empty | ||
end | ||
|
||
When /^I edit the page$/ do | ||
visit edit_admin_page_path(@page) | ||
end | ||
|
||
When /^I click the plus icon$/ do | ||
selenium.click "xpath=id('attachments')//img[@alt='Add']" | ||
end | ||
|
||
When /^I attach the Rails logo$/ do | ||
attach_file "file_input", "#{PageAttachmentsExtension.root}/spec/fixtures/rails.png" | ||
end | ||
|
||
When /^I delete the first attachment$/ do | ||
selenium.click "xpath=id('attachment_list')/li[1]//img[@alt='Delete']" | ||
end | ||
|
||
When /^I drag attachment 2 above attachment 1$/ do | ||
@attachment = @page.attachments[1] | ||
@attachment.position.should == 2 | ||
selenium.dragdrop("id=attachment_#{@attachment.id}", "0, -200") | ||
end | ||
|
||
When /^I save$/ do | ||
click_button "Save" | ||
response.should_not contain("errors") | ||
end | ||
|
||
Then /^the page should have a new attachment$/ do | ||
@page.reload.attachments.should_not be_empty | ||
end | ||
|
||
Then /^the page should have (\d+) attachment(?:s)?$/ do |number| | ||
@page.reload.attachments.length.should == number.to_i | ||
end | ||
|
||
Then /^attachment 2 should be in position 1$/ do | ||
@attachment.reload.position.should == 1 | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Sets up the Rails environment for Cucumber | ||
ENV["RAILS_ENV"] = "test" | ||
require File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment') | ||
|
||
require 'cucumber/rails/world' | ||
require 'cucumber/formatter/unicode' # Comment out this line if you don't want Cucumber Unicode support | ||
require 'webrat' | ||
raise "Update the version of Webrat you specify in test.rb." if Webrat.const_defined?(:VERSION) && Webrat::VERSION < '0.5.1' # Webrat 0.4.4 won't work with selenium-client 1.2.16 | ||
|
||
Webrat.configure do |config| | ||
config.mode = :selenium | ||
config.selenium_browser_key = "*chrome" | ||
end | ||
|
||
# this is necessary to have webrat "wait_for" the response body to be available | ||
# when writing steps that match against the response body returned by selenium | ||
World(Webrat::Selenium::Matchers) | ||
|
||
# Patch in attach_file functionality | ||
module Webrat | ||
class SeleniumSession | ||
def attach_file(field_locator, path, content_type = nil) | ||
fill_in(field_locator, :with => path) | ||
end | ||
end | ||
end | ||
|
||
require 'cucumber/rails/rspec' | ||
require 'dataset' | ||
|
||
module Dataset | ||
module Extensions # :nodoc: | ||
# Selenium can't handle transactions, so we have to disable them in Dataset | ||
module CucumberWorldNoTransactions # :nodoc: | ||
def dataset(*datasets, &block) | ||
add_dataset(*datasets, &block) | ||
|
||
load = nil | ||
$__cucumber_toplevel.Before do | ||
Dataset::Database::Base.new.clear # Empty all tables | ||
dataset_session.instance_variable_set("@load_stack", []) # notify load_stack that nothing's loaded | ||
load = dataset_session.load_datasets_for(self.class) | ||
extend_from_dataset_load(load) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
Cucumber::Rails::World.class_eval do | ||
include Dataset | ||
self.extend Dataset::Extensions::CucumberWorldNoTransactions | ||
datasets_directory "#{RADIANT_ROOT}/spec/datasets" | ||
Dataset::Resolver.default << (File.dirname(__FILE__) + "/../../spec/datasets") | ||
self.datasets_database_dump_path = "#{Rails.root}/tmp/dataset" | ||
dataset :pages_with_layouts, :users, :page_attachments | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def path_to(page_name) | ||
case page_name | ||
|
||
when /the homepage/i | ||
root_path | ||
|
||
when /edit the page/i | ||
edit_admin_page_path(@page) | ||
# Add more page name => path mappings here | ||
|
||
else | ||
raise "Can't find mapping from \"#{page_name}\" to a path." | ||
end | ||
end |
This file contains 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.