Sha256: 32124752a23268ee031fb85acbffa3d1e13767064ab5f495867b562d8c76fec3

Contents?: true

Size: 1.34 KB

Versions: 30

Compression:

Stored size: 1.34 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_form.address.present?.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

  it "2. Checking is nestes attributes ':comments' and ':address' are initialized" do
    post_form = described_class.new
    post_form.comments_attributes.should == {}
    post_form.address_attributes.should == {}
  end

end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
object_attorney-2.10.12 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.10.11 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.10.10 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.10.9 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.10.7 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.10.6 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.10.5 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.10.3 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.10.2 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.10.1 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.9.4 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.9.3 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.9.2 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.9.0 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.8.1 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.8.0 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.6.12 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.6.11 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.6.10 spec/object_attorney/post_with_comments_and_address_form_spec.rb
object_attorney-2.6.9 spec/object_attorney/post_with_comments_and_address_form_spec.rb