forked from ryanb/nested_form
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merging fxposter/rails31 with master
- Loading branch information
Showing
10 changed files
with
69 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
Gemfile.lock | ||
.bundle | ||
log | ||
gemfiles |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
appraise 'rails3' do | ||
gem 'rails', '~> 3.0.0' | ||
gem 'formtastic' | ||
end | ||
|
||
appraise 'rails3_1' do | ||
gem 'rails', '~> 3.1.0.rc4' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
source "http://rubygems.org" | ||
source "http://rubygems.org/" | ||
gemspec | ||
gem 'sqlite3' | ||
gem 'simple_form' | ||
gem 'formtastic' | ||
gem 'rake' | ||
gem 'appraisal' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
require 'rubygems' | ||
require 'appraisal' | ||
require 'rake' | ||
require 'rspec/core/rake_task' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,47 @@ | ||
require "spec_helper" | ||
|
||
describe NestedForm::ViewHelper do | ||
include RSpec::Rails::HelperExampleGroup | ||
|
||
before(:each) do | ||
@template = ActionView::Base.new | ||
@template.output_buffer = "" | ||
@template.stubs(:url_for).returns("") | ||
@template.stubs(:projects_path).returns("") | ||
@template.stubs(:protect_against_forgery?).returns(false) | ||
_routes.draw do | ||
resources :projects | ||
end | ||
end | ||
|
||
it "should pass nested form builder to form_for along with other options" do | ||
pending | ||
mock.proxy(@template).form_for(:first, :as => :second, :other => :arg, :builder => NestedForm::Builder) do |form_html| | ||
mock.proxy(_view).form_for(:first, :as => :second, :other => :arg, :builder => NestedForm::Builder) do |form_html| | ||
form_html | ||
end | ||
@template.nested_form_for(:first, :as => :second, :other => :arg) {"form"} | ||
_view.nested_form_for(:first, :as => :second, :other => :arg) {"form"} | ||
end | ||
|
||
it "should pass instance of NestedForm::Builder to nested_form_for block" do | ||
@template.nested_form_for(Project.new) do |f| | ||
_view.nested_form_for(Project.new) do |f| | ||
f.should be_instance_of(NestedForm::Builder) | ||
end | ||
end | ||
|
||
it "should pass instance of NestedForm::SimpleBuilder to simple_nested_form_for block" do | ||
@template.simple_nested_form_for(Project.new) do |f| | ||
_view.simple_nested_form_for(Project.new) do |f| | ||
f.should be_instance_of(NestedForm::SimpleBuilder) | ||
end | ||
end | ||
|
||
it "should pass instance of NestedForm::FormtasticBuilder to semantic_nested_form_for block" do | ||
@template.semantic_nested_form_for(Project.new) do |f| | ||
f.should be_instance_of(NestedForm::FormtasticBuilder) | ||
if defined?(NestedForm::FormtasticBuilder) | ||
it "should pass instance of NestedForm::FormtasticBuilder to semantic_nested_form_for block" do | ||
_view.semantic_nested_form_for(Project.new) do |f| | ||
f.should be_instance_of(NestedForm::FormtasticBuilder) | ||
end | ||
end | ||
end | ||
|
||
it "should append content to end of nested form" do | ||
@template.after_nested_form(:tasks) { @template.concat("123") } | ||
@template.after_nested_form(:milestones) { @template.concat("456") } | ||
@template.nested_form_for(Project.new) {} | ||
@template.output_buffer.should include("123456") | ||
_view.after_nested_form(:tasks) { _view.concat("123") } | ||
_view.after_nested_form(:milestones) { _view.concat("456") } | ||
_view.nested_form_for(Project.new) {} | ||
_view.output_buffer.should include("123456") | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,59 @@ | ||
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) | ||
$LOAD_PATH.unshift(File.dirname(__FILE__)) | ||
require "bundler/setup" | ||
require "rails" | ||
require 'action_view/railtie' | ||
Bundler.require(:default) | ||
require 'action_controller/railtie' | ||
require 'active_record' | ||
|
||
require "rails" | ||
require "nested_form" | ||
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => ':memory:') | ||
ActiveRecord::Migration.verbose = false | ||
|
||
# a fake app for initializing the railtie | ||
app = Class.new(Rails::Application) | ||
app.config.secret_token = "token" | ||
app.config.session_store :cookie_store, :key => "_myapp_session" | ||
app.config.active_support.deprecation = :log | ||
app.config.action_controller.perform_caching = false | ||
app.initialize! | ||
|
||
require 'action_controller' | ||
require 'active_record' | ||
require 'rspec/rails' | ||
|
||
RSpec.configure do |config| | ||
config.mock_with :mocha | ||
end | ||
|
||
class TablelessModel < ActiveRecord::Base | ||
def self.columns() @columns ||= []; end | ||
|
||
def self.column(name, sql_type = nil, default = nil, null = true) | ||
columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null) | ||
end | ||
|
||
def self.quoted_table_name | ||
name.pluralize.underscore | ||
end | ||
|
||
def quoted_id | ||
"0" | ||
ActiveRecord::Schema.define do | ||
create_table :projects, :force => true do |t| | ||
t.string :name | ||
end | ||
end | ||
|
||
class Project < TablelessModel | ||
column :name, :string | ||
class Project < ActiveRecord::Base | ||
# column :name, :string | ||
has_many :tasks | ||
accepts_nested_attributes_for :tasks | ||
end | ||
|
||
class Task < TablelessModel | ||
column :project_id, :integer | ||
column :name, :string | ||
ActiveRecord::Schema.define do | ||
create_table :tasks, :force => true do |t| | ||
t.integer :project_id | ||
t.string :name | ||
end | ||
end | ||
class Task < ActiveRecord::Base | ||
# column :project_id, :integer | ||
# column :name, :string | ||
belongs_to :project | ||
end | ||
|
||
class Milestone < TablelessModel | ||
column :task_id, :integer | ||
column :name, :string | ||
ActiveRecord::Schema.define do | ||
create_table :milestones, :force => true do |t| | ||
t.integer :task_id | ||
t.string :name | ||
end | ||
end | ||
class Milestone < ActiveRecord::Base | ||
# column :task_id, :integer | ||
# column :name, :string | ||
belongs_to :task | ||
end |