Skip to content

Commit 57f3278

Browse files
committed
merging fxposter/rails31 with master
2 parents d5b4838 + ad3275b commit 57f3278

10 files changed

+69
-51
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
Gemfile.lock
55
.bundle
66
log
7+
gemfiles

Appraisals

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
appraise 'rails3' do
2+
gem 'rails', '~> 3.0.0'
3+
gem 'formtastic'
4+
end
5+
6+
appraise 'rails3_1' do
7+
gem 'rails', '~> 3.1.0.rc4'
8+
end

Gemfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
source "http://rubygems.org"
1+
source "http://rubygems.org/"
22
gemspec
3+
gem 'sqlite3'
34
gem 'simple_form'
4-
gem 'formtastic'
5+
gem 'rake'
6+
gem 'appraisal'

README.rdoc

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ This gem only works with Rails 3. See the {rails2 branch}[https://github.com/rya
66

77
An example project showing how this works is available in the {complex-nested-forms/nested_form branch}[https://github.com/ryanb/complex-form-examples/tree/nested_form].
88

9+
910
== Setup
1011

1112
Add it to your Gemfile then run +bundle+ to install it.

Rakefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'rubygems'
2+
require 'appraisal'
23
require 'rake'
34
require 'rspec/core/rake_task'
45

lib/nested_form/builder_mixin.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ def link_to_remove(*args, &block)
4848
hidden_field(:_destroy) + @template.link_to(*args, &block)
4949
end
5050

51-
def fields_for_with_nested_attributes(association_name, args, block)
51+
def fields_for_with_nested_attributes(association_name, *args)
5252
# TODO Test this better
53-
block ||= Proc.new { |fields| @template.render(:partial => "#{association_name.to_s.singularize}_fields", :locals => {:f => fields}) }
53+
block = args.pop || Proc.new { |fields| @template.render(:partial => "#{association_name.to_s.singularize}_fields", :locals => {:f => fields}) }
5454
@fields ||= {}
5555
@fields[association_name] = block
56-
super(association_name, args, block)
56+
super(association_name, *(args << block))
5757
end
5858

5959
def fields_for_nested_model(name, object, options, block)

nested_form.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ Gem::Specification.new do |s|
1010
s.files = Dir["{lib,spec}/**/*", "[A-Z]*"] - ["Gemfile.lock"]
1111
s.require_path = "lib"
1212

13-
s.add_development_dependency "rspec-rails", "~> 2.1.0"
13+
s.add_development_dependency "rspec-rails", "~> 2.6.0"
1414
s.add_development_dependency "mocha"
15-
s.add_development_dependency "rails", "~> 3.0.0"
15+
# s.add_development_dependency "rails", "~> 3.1.0.rc"
1616

1717
s.rubyforge_project = s.name
1818
s.required_rubygems_version = ">= 1.3.4"

spec/nested_form/builder_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "spec_helper"
22

3-
[NestedForm::Builder, NestedForm::SimpleBuilder, NestedForm::FormtasticBuilder].each do |builder|
3+
[NestedForm::Builder, NestedForm::SimpleBuilder, defined?(NestedForm::FormtasticBuilder) ? NestedForm::FormtasticBuilder : nil].compact.each do |builder|
44
describe builder do
55
describe "with no options" do
66
before(:each) do

spec/nested_form/view_helper_spec.rb

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
11
require "spec_helper"
22

33
describe NestedForm::ViewHelper do
4+
include RSpec::Rails::HelperExampleGroup
5+
46
before(:each) do
5-
@template = ActionView::Base.new
6-
@template.output_buffer = ""
7-
@template.stubs(:url_for).returns("")
8-
@template.stubs(:projects_path).returns("")
9-
@template.stubs(:protect_against_forgery?).returns(false)
7+
_routes.draw do
8+
resources :projects
9+
end
1010
end
1111

1212
it "should pass nested form builder to form_for along with other options" do
1313
pending
14-
mock.proxy(@template).form_for(:first, :as => :second, :other => :arg, :builder => NestedForm::Builder) do |form_html|
14+
mock.proxy(_view).form_for(:first, :as => :second, :other => :arg, :builder => NestedForm::Builder) do |form_html|
1515
form_html
1616
end
17-
@template.nested_form_for(:first, :as => :second, :other => :arg) {"form"}
17+
_view.nested_form_for(:first, :as => :second, :other => :arg) {"form"}
1818
end
1919

2020
it "should pass instance of NestedForm::Builder to nested_form_for block" do
21-
@template.nested_form_for(Project.new) do |f|
21+
_view.nested_form_for(Project.new) do |f|
2222
f.should be_instance_of(NestedForm::Builder)
2323
end
2424
end
2525

2626
it "should pass instance of NestedForm::SimpleBuilder to simple_nested_form_for block" do
27-
@template.simple_nested_form_for(Project.new) do |f|
27+
_view.simple_nested_form_for(Project.new) do |f|
2828
f.should be_instance_of(NestedForm::SimpleBuilder)
2929
end
3030
end
3131

32-
it "should pass instance of NestedForm::FormtasticBuilder to semantic_nested_form_for block" do
33-
@template.semantic_nested_form_for(Project.new) do |f|
34-
f.should be_instance_of(NestedForm::FormtasticBuilder)
32+
if defined?(NestedForm::FormtasticBuilder)
33+
it "should pass instance of NestedForm::FormtasticBuilder to semantic_nested_form_for block" do
34+
_view.semantic_nested_form_for(Project.new) do |f|
35+
f.should be_instance_of(NestedForm::FormtasticBuilder)
36+
end
3537
end
3638
end
3739

3840
it "should append content to end of nested form" do
39-
@template.after_nested_form(:tasks) { @template.concat("123") }
40-
@template.after_nested_form(:milestones) { @template.concat("456") }
41-
@template.nested_form_for(Project.new) {}
42-
@template.output_buffer.should include("123456")
41+
_view.after_nested_form(:tasks) { _view.concat("123") }
42+
_view.after_nested_form(:milestones) { _view.concat("456") }
43+
_view.nested_form_for(Project.new) {}
44+
_view.output_buffer.should include("123456")
4345
end
4446
end
4547

spec/spec_helper.rb

+30-27
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,59 @@
11
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
22
$LOAD_PATH.unshift(File.dirname(__FILE__))
33
require "bundler/setup"
4+
require "rails"
5+
require 'action_view/railtie'
46
Bundler.require(:default)
7+
require 'action_controller/railtie'
8+
require 'active_record'
59

6-
require "rails"
7-
require "nested_form"
10+
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:')
11+
ActiveRecord::Migration.verbose = false
812

913
# a fake app for initializing the railtie
1014
app = Class.new(Rails::Application)
1115
app.config.secret_token = "token"
1216
app.config.session_store :cookie_store, :key => "_myapp_session"
1317
app.config.active_support.deprecation = :log
18+
app.config.action_controller.perform_caching = false
1419
app.initialize!
1520

16-
require 'action_controller'
17-
require 'active_record'
1821
require 'rspec/rails'
19-
2022
RSpec.configure do |config|
2123
config.mock_with :mocha
2224
end
2325

24-
class TablelessModel < ActiveRecord::Base
25-
def self.columns() @columns ||= []; end
26-
27-
def self.column(name, sql_type = nil, default = nil, null = true)
28-
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
29-
end
30-
31-
def self.quoted_table_name
32-
name.pluralize.underscore
33-
end
34-
35-
def quoted_id
36-
"0"
26+
ActiveRecord::Schema.define do
27+
create_table :projects, :force => true do |t|
28+
t.string :name
3729
end
3830
end
39-
40-
class Project < TablelessModel
41-
column :name, :string
31+
class Project < ActiveRecord::Base
32+
# column :name, :string
4233
has_many :tasks
4334
accepts_nested_attributes_for :tasks
4435
end
4536

46-
class Task < TablelessModel
47-
column :project_id, :integer
48-
column :name, :string
37+
ActiveRecord::Schema.define do
38+
create_table :tasks, :force => true do |t|
39+
t.integer :project_id
40+
t.string :name
41+
end
42+
end
43+
class Task < ActiveRecord::Base
44+
# column :project_id, :integer
45+
# column :name, :string
4946
belongs_to :project
5047
end
5148

52-
class Milestone < TablelessModel
53-
column :task_id, :integer
54-
column :name, :string
49+
ActiveRecord::Schema.define do
50+
create_table :milestones, :force => true do |t|
51+
t.integer :task_id
52+
t.string :name
53+
end
54+
end
55+
class Milestone < ActiveRecord::Base
56+
# column :task_id, :integer
57+
# column :name, :string
5558
belongs_to :task
5659
end

0 commit comments

Comments
 (0)