diff --git a/.gitignore b/.gitignore index d1113c7..2228b00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,18 +1,18 @@ -coverage -.DS_Store -pkg -doc -ri -email.txt -.svn -log -.project -.loadpath -*.swp -results -test_apps -*.tmproj *.log *.pid +*.swp +*.tmproj +.DS_Store +.loadpath +.project bin +coverage +doc +email.txt +log +pkg +results +ri +test_apps +tmp vendor/gems diff --git a/spec/integration/rails/app/controllers/webrat_controller.rb b/spec/integration/rails/app/controllers/webrat_controller.rb index 9f88f52..0fc3ccc 100644 --- a/spec/integration/rails/app/controllers/webrat_controller.rb +++ b/spec/integration/rails/app/controllers/webrat_controller.rb @@ -43,4 +43,16 @@ class WebratController < ApplicationController def within end + def file + @album = Album.new + + 3.times { @album.photos.build } + end + + def post_file + album = Album.new(params[:album]) + + render :text => "#{album.photos.size} photos." + end + end diff --git a/spec/integration/rails/app/models/album.rb b/spec/integration/rails/app/models/album.rb new file mode 100644 index 0000000..b64b277 --- /dev/null +++ b/spec/integration/rails/app/models/album.rb @@ -0,0 +1,4 @@ +class Album < ActiveRecord::Base + has_many :photos + accepts_nested_attributes_for :photos +end diff --git a/spec/integration/rails/app/models/photo.rb b/spec/integration/rails/app/models/photo.rb new file mode 100644 index 0000000..fa1886c --- /dev/null +++ b/spec/integration/rails/app/models/photo.rb @@ -0,0 +1,3 @@ +class Photo < ActiveRecord::Base + belongs_to :album +end diff --git a/spec/integration/rails/app/views/webrat/file.html.erb b/spec/integration/rails/app/views/webrat/file.html.erb new file mode 100644 index 0000000..8e6ee76 --- /dev/null +++ b/spec/integration/rails/app/views/webrat/file.html.erb @@ -0,0 +1,14 @@ +<%- count = 0 %> + +<% form_for(@album, :url => post_file_path, :html => {:multipart => true}) do |f| %> +

+ <% f.fields_for :photos do |uf| %> + <%= uf.label :image, "Photo #{count += 1}" %> + <%= uf.file_field :image %>
+ <% end %> +

+ +

+ <%= f.submit 'Create' %> +

+<% end %> diff --git a/spec/integration/rails/config/database.yml b/spec/integration/rails/config/database.yml new file mode 100644 index 0000000..d9a8040 --- /dev/null +++ b/spec/integration/rails/config/database.yml @@ -0,0 +1,7 @@ +development: + adapter: sqlite3 + database: "tmp/development.sqlite3" + +test: + adapter: sqlite3 + database: "tmp/test.sqlite3" diff --git a/spec/integration/rails/config/environment.rb b/spec/integration/rails/config/environment.rb index ed4cad4..84cb003 100644 --- a/spec/integration/rails/config/environment.rb +++ b/spec/integration/rails/config/environment.rb @@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'boot') Rails::Initializer.run do |config| - config.frameworks -= [ :active_record, :active_resource, :action_mailer ] + # config.frameworks -= [ :active_record, :active_resource, :action_mailer ] config.time_zone = 'UTC' config.action_controller.session = { :session_key => '_rails_app_session', diff --git a/spec/integration/rails/config/routes.rb b/spec/integration/rails/config/routes.rb index ab2ab3e..bd96a93 100644 --- a/spec/integration/rails/config/routes.rb +++ b/spec/integration/rails/config/routes.rb @@ -13,6 +13,8 @@ ActionController::Routing::Routes.draw do |map| webrat.redirect_to_show_params "/redirect_to_show_params", :action => "redirect_to_show_params" webrat.show_params "/show_params", :action => "show_params" webrat.within "/within", :action => "within" + webrat.file "/file", :action => "file" + webrat.post_file "/post_file", :action => "post_file" webrat.root :action => "form" end diff --git a/spec/integration/rails/db/schema.rb b/spec/integration/rails/db/schema.rb new file mode 100644 index 0000000..aed30f1 --- /dev/null +++ b/spec/integration/rails/db/schema.rb @@ -0,0 +1,10 @@ +ActiveRecord::Schema.define(:version => 0) do + create_table :albums, :force => true do |t| + t.string :name + end + + create_table :photos, :force => true do |t| + t.string :image + t.integer :album_id + end +end diff --git a/spec/integration/rails/test/fixtures/image.jpg b/spec/integration/rails/test/fixtures/image.jpg new file mode 100644 index 0000000..3c011f5 Binary files /dev/null and b/spec/integration/rails/test/fixtures/image.jpg differ diff --git a/spec/integration/rails/test/integration/webrat_test.rb b/spec/integration/rails/test/integration/webrat_test.rb index e06f265..24b0c18 100644 --- a/spec/integration/rails/test/integration/webrat_test.rb +++ b/spec/integration/rails/test/integration/webrat_test.rb @@ -107,6 +107,18 @@ class WebratTest < ActionController::IntegrationTest end end + test "post nested params for files" do + visit "/file" + + attach_file "Photo 1", "test/fixtures/image.jpg", "image/jpeg" + attach_file "Photo 2", "test/fixtures/image.jpg", "image/jpeg" + attach_file "Photo 3", "test/fixtures/image.jpg", "image/jpeg" + + click_button "Create" + + assert_contain "3 photos." + end + # Firefox detects and prevents infinite redirects under Selenium unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium' test "should detect infinite redirects" do diff --git a/spec/integration/rails/test/test_helper.rb b/spec/integration/rails/test/test_helper.rb index f3ea865..e2e6cc5 100644 --- a/spec/integration/rails/test/test_helper.rb +++ b/spec/integration/rails/test/test_helper.rb @@ -1,5 +1,6 @@ ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") +load File.expand_path(File.dirname(__FILE__) + "/../db/schema.rb") require 'test_help' # begin