Compare commits
1 Commits
master
...
rails_atta
Author | SHA1 | Date | |
---|---|---|---|
|
a3abe5782c |
28
.gitignore
vendored
28
.gitignore
vendored
@ -1,18 +1,18 @@
|
|||||||
coverage
|
|
||||||
.DS_Store
|
|
||||||
pkg
|
|
||||||
doc
|
|
||||||
ri
|
|
||||||
email.txt
|
|
||||||
.svn
|
|
||||||
log
|
|
||||||
.project
|
|
||||||
.loadpath
|
|
||||||
*.swp
|
|
||||||
results
|
|
||||||
test_apps
|
|
||||||
*.tmproj
|
|
||||||
*.log
|
*.log
|
||||||
*.pid
|
*.pid
|
||||||
|
*.swp
|
||||||
|
*.tmproj
|
||||||
|
.DS_Store
|
||||||
|
.loadpath
|
||||||
|
.project
|
||||||
bin
|
bin
|
||||||
|
coverage
|
||||||
|
doc
|
||||||
|
email.txt
|
||||||
|
log
|
||||||
|
pkg
|
||||||
|
results
|
||||||
|
ri
|
||||||
|
test_apps
|
||||||
|
tmp
|
||||||
vendor/gems
|
vendor/gems
|
||||||
|
@ -110,7 +110,7 @@ module Webrat
|
|||||||
when :rack, :sinatra
|
when :rack, :sinatra
|
||||||
Rack::Utils.parse_nested_query(query_string)
|
Rack::Utils.parse_nested_query(query_string)
|
||||||
else
|
else
|
||||||
Hash[query_string.split('&').map {|query| [ query.split('=').first, query.split('=').last ]}]
|
query_string.split('&').map {|query| { query.split('=').first => query.split('=').last }}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -43,4 +43,16 @@ class WebratController < ApplicationController
|
|||||||
def within
|
def within
|
||||||
end
|
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
|
end
|
||||||
|
4
spec/integration/rails/app/models/album.rb
Normal file
4
spec/integration/rails/app/models/album.rb
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
class Album < ActiveRecord::Base
|
||||||
|
has_many :photos
|
||||||
|
accepts_nested_attributes_for :photos
|
||||||
|
end
|
3
spec/integration/rails/app/models/photo.rb
Normal file
3
spec/integration/rails/app/models/photo.rb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class Photo < ActiveRecord::Base
|
||||||
|
belongs_to :album
|
||||||
|
end
|
14
spec/integration/rails/app/views/webrat/file.html.erb
Normal file
14
spec/integration/rails/app/views/webrat/file.html.erb
Normal file
@ -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
spec/integration/rails/config/database.yml
Normal file
7
spec/integration/rails/config/database.yml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
development:
|
||||||
|
adapter: sqlite3
|
||||||
|
database: "tmp/development.sqlite3"
|
||||||
|
|
||||||
|
test:
|
||||||
|
adapter: sqlite3
|
||||||
|
database: "tmp/test.sqlite3"
|
@ -3,7 +3,7 @@
|
|||||||
require File.join(File.dirname(__FILE__), 'boot')
|
require File.join(File.dirname(__FILE__), 'boot')
|
||||||
|
|
||||||
Rails::Initializer.run do |config|
|
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.time_zone = 'UTC'
|
||||||
config.action_controller.session = {
|
config.action_controller.session = {
|
||||||
:session_key => '_rails_app_session',
|
:session_key => '_rails_app_session',
|
||||||
|
@ -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.redirect_to_show_params "/redirect_to_show_params", :action => "redirect_to_show_params"
|
||||||
webrat.show_params "/show_params", :action => "show_params"
|
webrat.show_params "/show_params", :action => "show_params"
|
||||||
webrat.within "/within", :action => "within"
|
webrat.within "/within", :action => "within"
|
||||||
|
webrat.file "/file", :action => "file"
|
||||||
|
webrat.post_file "/post_file", :action => "post_file"
|
||||||
|
|
||||||
webrat.root :action => "form"
|
webrat.root :action => "form"
|
||||||
end
|
end
|
||||||
|
10
spec/integration/rails/db/schema.rb
Normal file
10
spec/integration/rails/db/schema.rb
Normal file
@ -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
|
BIN
spec/integration/rails/test/fixtures/image.jpg
vendored
Normal file
BIN
spec/integration/rails/test/fixtures/image.jpg
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
@ -107,6 +107,18 @@ class WebratTest < ActionController::IntegrationTest
|
|||||||
end
|
end
|
||||||
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
|
# Firefox detects and prevents infinite redirects under Selenium
|
||||||
unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium'
|
unless ENV['WEBRAT_INTEGRATION_MODE'] == 'selenium'
|
||||||
test "should detect infinite redirects" do
|
test "should detect infinite redirects" do
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
ENV["RAILS_ENV"] = "test"
|
ENV["RAILS_ENV"] = "test"
|
||||||
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
|
||||||
|
load File.expand_path(File.dirname(__FILE__) + "/../db/schema.rb")
|
||||||
require 'test_help'
|
require 'test_help'
|
||||||
|
|
||||||
# begin
|
# begin
|
||||||
|
@ -48,22 +48,4 @@ describe "Multiple nested params" do
|
|||||||
webrat_session.should_receive(:post).with("/family", params)
|
webrat_session.should_receive(:post).with("/family", params)
|
||||||
click_button
|
click_button
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should correctly construct a query string" do
|
|
||||||
Webrat.configuration.mode = :mechanize
|
|
||||||
|
|
||||||
with_html <<-HTML
|
|
||||||
<html>
|
|
||||||
<form method="get" action="/search">
|
|
||||||
<input type="text" name="query" value="my-query" />
|
|
||||||
<input type="submit" />
|
|
||||||
</form>
|
|
||||||
</html>
|
|
||||||
HTML
|
|
||||||
|
|
||||||
params = { "query" => "my-query" }
|
|
||||||
|
|
||||||
webrat_session.should_receive(:get).with("/search", params)
|
|
||||||
click_button
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user