Sha256: 605840cd5a9571f77ad1640b6d88d2eb813f8f799c0466b8a4195b5599338331

Contents?: true

Size: 1.08 KB

Versions: 7

Compression:

Stored size: 1.08 KB

Contents

require "spec_helper"

describe PostWithCommentsAndAddressForm do

  it "1. Creating a 'Post' with nested 'Comment's and a single 'Address'" do
    params = {
      post: {
        title: 'First post',
        body: 'post body',
        comments_attributes: {
          "0" => { body: "body1" },
          "1" => { body: "" }
        },
        address_attributes: {
          street: 'street',
          city: 'city'
        }
      }
    }

    post_form = described_class.new(params[:post])

    post_form.save.should == true
    
    Post.all.count.should == 1
    post = Post.first
    post.title.should == 'First post'
    post.body.should == 'post body'
    
    post.comments.count.should == 2
    
    comment = post.comments.first
    comment.post_id.should == post.id
    comment.body.should == 'body1'

    comment = post.comments.second
    comment.post_id.should == post.id
    comment.body.should == ''

    post.address.present?.should == true
    address = Address.first
    address.post_id.should == post.id
    address.street.should == 'street'
    address.city.should == 'city'
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
object_attorney-2.2.7 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.2.6 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.2.5 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.2.4 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.2.3 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.2.2 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.2.1 spec/object_attorney/post_with_comments_and_address_form_spec.rb