Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add spec that shows nested file inputs.

  • Loading branch information...
commit a3abe5782c623cda42410e02e9e02e811d6e4a8c 1 parent 8f637e6
Damian Janowski djanowski authored
22 .gitignore
... ... @@ -1,18 +1,18 @@
1   -coverage
  1 +*.log
  2 +*.pid
  3 +*.swp
  4 +*.tmproj
2 5 .DS_Store
3   -pkg
  6 +.loadpath
  7 +.project
  8 +bin
  9 +coverage
4 10 doc
5   -ri
6 11 email.txt
7   -.svn
8 12 log
9   -.project
10   -.loadpath
11   -*.swp
  13 +pkg
12 14 results
  15 +ri
13 16 test_apps
14   -*.tmproj
15   -*.log
16   -*.pid
17   -bin
  17 +tmp
18 18 vendor/gems
12 spec/integration/rails/app/controllers/webrat_controller.rb
@@ -43,4 +43,16 @@ def show_params
43 43 def within
44 44 end
45 45
  46 + def file
  47 + @album = Album.new
  48 +
  49 + 3.times { @album.photos.build }
  50 + end
  51 +
  52 + def post_file
  53 + album = Album.new(params[:album])
  54 +
  55 + render :text => "#{album.photos.size} photos."
  56 + end
  57 +
46 58 end
4 spec/integration/rails/app/models/album.rb
... ... @@ -0,0 +1,4 @@
  1 +class Album < ActiveRecord::Base
  2 + has_many :photos
  3 + accepts_nested_attributes_for :photos
  4 +end
3  spec/integration/rails/app/models/photo.rb
... ... @@ -0,0 +1,3 @@
  1 +class Photo < ActiveRecord::Base
  2 + belongs_to :album
  3 +end
14 spec/integration/rails/app/views/webrat/file.html.erb
... ... @@ -0,0 +1,14 @@
  1 +<%- count = 0 %>
  2 +
  3 +<% form_for(@album, :url => post_file_path, :html => {:multipart => true}) do |f| %>
  4 + <p>
  5 + <% f.fields_for :photos do |uf| %>
  6 + <%= uf.label :image, "Photo #{count += 1}" %>
  7 + <%= uf.file_field :image %><br/>
  8 + <% end %>
  9 + </p>
  10 +
  11 + <p>
  12 + <%= f.submit 'Create' %>
  13 + </p>
  14 +<% end %>
7 spec/integration/rails/config/database.yml
... ... @@ -0,0 +1,7 @@
  1 +development:
  2 + adapter: sqlite3
  3 + database: "tmp/development.sqlite3"
  4 +
  5 +test:
  6 + adapter: sqlite3
  7 + database: "tmp/test.sqlite3"
2  spec/integration/rails/config/environment.rb
@@ -3,7 +3,7 @@
3 3 require File.join(File.dirname(__FILE__), 'boot')
4 4
5 5 Rails::Initializer.run do |config|
6   - config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
  6 + # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
7 7 config.time_zone = 'UTC'
8 8 config.action_controller.session = {
9 9 :session_key => '_rails_app_session',
2  spec/integration/rails/config/routes.rb
@@ -13,6 +13,8 @@
13 13 webrat.redirect_to_show_params "/redirect_to_show_params", :action => "redirect_to_show_params"
14 14 webrat.show_params "/show_params", :action => "show_params"
15 15 webrat.within "/within", :action => "within"
  16 + webrat.file "/file", :action => "file"
  17 + webrat.post_file "/post_file", :action => "post_file"
16 18
17 19 webrat.root :action => "form"
18 20 end
10 spec/integration/rails/db/schema.rb
... ... @@ -0,0 +1,10 @@
  1 +ActiveRecord::Schema.define(:version => 0) do
  2 + create_table :albums, :force => true do |t|
  3 + t.string :name
  4 + end
  5 +
  6 + create_table :photos, :force => true do |t|
  7 + t.string :image
  8 + t.integer :album_id
  9 + end
  10 +end
BIN  spec/integration/rails/test/fixtures/image.jpg
12 spec/integration/rails/test/integration/webrat_test.rb
@@ -107,6 +107,18 @@ def object.id
107 107 end
108 108 end
109 109
  110 + test "post nested params for files" do
  111 + visit "/file"
  112 +
  113 + attach_file "Photo 1", "test/fixtures/image.jpg", "image/jpeg"
  114 + attach_file "Photo 2", "test/fixtures/image.jpg", "image/jpeg"
  115 + attach_file "Photo 3", "test/fixtures/image.jpg", "image/jpeg"
  116 +
  117 + click_button "Create"
  118 +
  119 + assert_contain "3 photos."
  120 + end
  121 +
110 122 # Firefox detects and prevents infinite redirects under Selenium
111 123 unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium'
112 124 test "should detect infinite redirects" do
1  spec/integration/rails/test/test_helper.rb
... ... @@ -1,5 +1,6 @@
1 1 ENV["RAILS_ENV"] = "test"
2 2 require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
  3 +load File.expand_path(File.dirname(__FILE__) + "/../db/schema.rb")
3 4 require 'test_help'
4 5
5 6 # begin

0 comments on commit a3abe57

Please sign in to comment.
Something went wrong with that request. Please try again.