Sha256: 75a56e9b4da9cabbbdcabd86520a7227e3d619f560c75766d40bb7147aa5dea0

Contents?: true

Size: 1.56 KB

Versions: 7

Compression:

Stored size: 1.56 KB

Contents

require "spec_helper"

describe 'Testing the #reset_nested_objects method' do

  it "1. Creating 'Comments' from 'PostWithCommentForm::Base', adding another, manually and expecting the form_object to not knowing it.", current: true do
    params = {
      post: {
        title: 'new title',
        comments_attributes: {
          "0" => { body: "body1" },
          "1" => { body: "1" }
        }
      }
    }

    post_form = PostWithCommentForm::Base.new(params[:post])

    post_form.save.should == true

    Post.all.count.should == 1
    Comment.all.count.should == 2

    post_form.comments.length.should == 2

    post = Post.first
    post.comments.create(body: 'new_comment')

    post_form.post.reload
    post_form.post.comments.length.should == 3
    post_form.comments.length.should == 2
  end

  it "1. Creating 'Comments' from 'PostWithCommentForm::Base', adding another, manually and expecting the form_object to know about it.", current: true do
    params = {
      post: {
        title: 'new title',
        comments_attributes: {
          "0" => { body: "body1" },
          "1" => { body: "1" }
        }
      }
    }

    post_form = PostWithCommentForm::Base.new(params[:post])

    post_form.save.should == true

    Post.all.count.should == 1
    Comment.all.count.should == 2

    post_form.comments.length.should == 2

    post = Post.first
    post.comments.create(body: 'new_comment')

    post_form.post.reload
    post_form.post.comments.length.should == 3

    post_form.reset_nested_objects(:comments)
    post_form.comments.length.should == 3
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
object_attorney-2.10.12 spec/object_attorney/nested_objects_spec.rb
object_attorney-2.10.11 spec/object_attorney/nested_objects_spec.rb
object_attorney-2.10.10 spec/object_attorney/nested_objects_spec.rb
object_attorney-2.10.9 spec/object_attorney/nested_objects_spec.rb
object_attorney-2.10.7 spec/object_attorney/nested_objects_spec.rb
object_attorney-2.10.6 spec/object_attorney/nested_objects_spec.rb
object_attorney-2.10.5 spec/object_attorney/nested_objects_spec.rb