Added tests for link_to_add_association.
This commit is contained in:
parent
8db3114134
commit
84ce937e50
|
@ -1,7 +1,6 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Cocoon do
|
||||
|
||||
class TestClass < ActionView::Base
|
||||
|
||||
end
|
||||
|
@ -11,4 +10,25 @@ describe Cocoon do
|
|||
it { should respond_to(:link_to_add_association) }
|
||||
it { should respond_to(:link_to_remove_association) }
|
||||
|
||||
context "link_to_add_association" do
|
||||
before(:each) do
|
||||
@tester = TestClass.new
|
||||
@post = Post.new
|
||||
@form_obj = stub(:object => @post)
|
||||
@tester.stub(:render_association).and_return('form')
|
||||
end
|
||||
|
||||
it "should accept a name without a block" do
|
||||
result = @tester.link_to_add_association('add something', @form_obj, :comments)
|
||||
result.to_s.should == '<div id="comment_fields_template" style="display:none;">form</div><a href="#" class="add_fields" data-association="comment">add something</a>'
|
||||
end
|
||||
|
||||
it "should work with a block" do
|
||||
result = @tester.link_to_add_association(@form_obj, :comments) do
|
||||
"some long name"
|
||||
end
|
||||
result.to_s.should == '<div id="comment_fields_template" style="display:none;">form</div><a href="#" class="add_fields" data-association="comment">some long name</a>'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
class Comment < ActiveRecord::Base
|
||||
belongs_to :post
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
class Post < ActiveRecord::Base
|
||||
has_many :comments
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
class CreatePosts < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :posts do |t|
|
||||
t.string :title
|
||||
t.text :body
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :posts
|
||||
end
|
||||
end
|
|
@ -0,0 +1,15 @@
|
|||
class CreateComments < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :comments do |t|
|
||||
t.text :body
|
||||
t.string :author
|
||||
t.integer :post_id
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :comments
|
||||
end
|
||||
end
|
|
@ -0,0 +1,30 @@
|
|||
# This file is auto-generated from the current state of the database. Instead
|
||||
# of editing this file, please use the migrations feature of Active Record to
|
||||
# incrementally modify your database, and then regenerate this schema definition.
|
||||
#
|
||||
# Note that this schema.rb definition is the authoritative source for your
|
||||
# database schema. If you need to create the application database on another
|
||||
# system, you should be using db:schema:load, not running all the migrations
|
||||
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
||||
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20110306212250) do
|
||||
|
||||
create_table "comments", :force => true do |t|
|
||||
t.text "body"
|
||||
t.string "author"
|
||||
t.integer "post_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "posts", :force => true do |t|
|
||||
t.string "title"
|
||||
t.text "body"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue