Skip to content

Commit

Permalink
Add spec that shows nested file inputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
djanowski committed May 14, 2010
1 parent 8f637e6 commit a3abe57
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 12 deletions.
22 changes: 11 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
coverage
*.log
*.pid
*.swp
*.tmproj
.DS_Store
pkg
.loadpath
.project
bin
coverage
doc
ri
email.txt
.svn
log
.project
.loadpath
*.swp
pkg
results
ri
test_apps
*.tmproj
*.log
*.pid
bin
tmp
vendor/gems
12 changes: 12 additions & 0 deletions spec/integration/rails/app/controllers/webrat_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@ def show_params
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
4 changes: 4 additions & 0 deletions spec/integration/rails/app/models/album.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Album < ActiveRecord::Base
has_many :photos
accepts_nested_attributes_for :photos
end
3 changes: 3 additions & 0 deletions spec/integration/rails/app/models/photo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Photo < ActiveRecord::Base
belongs_to :album
end
14 changes: 14 additions & 0 deletions spec/integration/rails/app/views/webrat/file.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%- count = 0 %>
<% form_for(@album, :url => post_file_path, :html => {:multipart => true}) do |f| %>
<p>
<% f.fields_for :photos do |uf| %>
<%= uf.label :image, "Photo #{count += 1}" %>
<%= uf.file_field :image %><br/>
<% end %>
</p>

<p>
<%= f.submit 'Create' %>
</p>
<% end %>
7 changes: 7 additions & 0 deletions spec/integration/rails/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
development:
adapter: sqlite3
database: "tmp/development.sqlite3"

test:
adapter: sqlite3
database: "tmp/test.sqlite3"
2 changes: 1 addition & 1 deletion spec/integration/rails/config/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions spec/integration/rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
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
Expand Down
10 changes: 10 additions & 0 deletions spec/integration/rails/db/schema.rb
Original file line number Diff line number Diff line change
@@ -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
Binary file added spec/integration/rails/test/fixtures/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions spec/integration/rails/test/integration/webrat_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,18 @@ def object.id
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
Expand Down
1 change: 1 addition & 0 deletions spec/integration/rails/test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a3abe57

Please sign in to comment.