From a3abe5782c623cda42410e02e9e02e811d6e4a8c Mon Sep 17 00:00:00 2001 From: Damian Janowski Date: Fri, 14 May 2010 13:20:07 -0300 Subject: [PATCH] Add spec that shows nested file inputs. --- .gitignore | 28 +++++++++--------- .../app/controllers/webrat_controller.rb | 12 ++++++++ spec/integration/rails/app/models/album.rb | 4 +++ spec/integration/rails/app/models/photo.rb | 3 ++ .../rails/app/views/webrat/file.html.erb | 14 +++++++++ spec/integration/rails/config/database.yml | 7 +++++ spec/integration/rails/config/environment.rb | 2 +- spec/integration/rails/config/routes.rb | 2 ++ spec/integration/rails/db/schema.rb | 10 +++++++ .../integration/rails/test/fixtures/image.jpg | Bin 0 -> 3512 bytes .../rails/test/integration/webrat_test.rb | 12 ++++++++ spec/integration/rails/test/test_helper.rb | 1 + 12 files changed, 80 insertions(+), 15 deletions(-) create mode 100644 spec/integration/rails/app/models/album.rb create mode 100644 spec/integration/rails/app/models/photo.rb create mode 100644 spec/integration/rails/app/views/webrat/file.html.erb create mode 100644 spec/integration/rails/config/database.yml create mode 100644 spec/integration/rails/db/schema.rb create mode 100644 spec/integration/rails/test/fixtures/image.jpg 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 0000000000000000000000000000000000000000..3c011f55d8b6b517c826d864a960331382a19f51 GIT binary patch literal 3512 zcmb7Gc{J4h9{w>Hd&a)zouSB1vSdm2HS18e*UnJZB4iiMs4$k0eHpvAA$yXGOnQ+S zOAMxweG*wGORnB?@40{9=kxiV^F8PDJkRI(^KIO#K_3Z2nI8=F*CEUo&(Ipeu0gZ{rCU3$#3~@ z)p@frf*F4^{y&_(10alm4xj^~fdI4+8W4o$Yyc1j0ML0>5DoBOFr0^>2SChp=TlXV z^XwoHE#3KErhf=Dv>-Zq1~7yZfHE?1DZ*}AGjof%ha~XuD)C>ssvDY!E*n1=3efFU{( zZG%0|W&zgokhBmG1h@grXbEla1`{mbXfS(TvU?_0;*dFqjyX6vs$=U)t~3y?Nt9r| zdD0<132ED;ZJ|}2I|Ej2KL0ta)_kc%AzjolZW)=X7ujQEiS~9tbs+p2wnriBi{b)O z5*nPDu)uzAnP0;V5kw@i&+pzUmkC*8(Sb$W*v#=QUak;6VIg8)xO5F-dut*w%5;_? zI{AtE)tfA){585wa9k!RaF{!6qtnAJDFjAna>Z6rrRuiP4qw+V$g?g4UKBlXxwE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-;oPdudtbK|7-Yal9i^(hD1RQk@b`JgfohIG=dfk zI1S14TVHG@X27TN5YSmkn9uD=zOOe@TRw;d&N~*y)FM1C+iJnouP8Y91k|D zQ)2@JdtW>>>EG+^k7Yr5P^s@j-Y69Z=o^ml8@1~}_j&Ia4qR7`&ll8*RX0O3$$pa4 zeE%b*7~15Y+#_8ebq1_-hBqjv#JV}gOgTwOl}lF3wCaDaErHu1yX`fh29KbDo$Pwi zrG-1(UyMvdMLilk>3bLZ%U)$OpjN&#tc;Ae;&z3`dG`=^RUG*}_eK3`%Wpw+DzKjI z&FSHuqzw~F1=yvv%@ETS^_SP`#UMd1)#tMG*Y=DZPRq2+ESX|$?MJS(e6TbKoz%?L zFt}@Ds(ol16yN#)ZupM&ZDpoSy?iW-4abSoUQDtHT`6666s_-k)QLTB-oVaChow5Y tZhf3iczrTlqvZoEhtxjiqY-ocbJyAs{>ItNzX6BDU+w?^ literal 0 HcmV?d00001 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