Sha256: 0456450f758228a21ec134841204b9c22a5612876ef1f7925e573acd40df846a

Contents?: true

Size: 1022 Bytes

Versions: 20

Compression:

Stored size: 1022 Bytes

Contents

require "spec_helper"

describe PostWithOnlyExistingCommentsForm do

  it "1. Editing nested 'Comments' inside a PostForm that only accepts existing Comments changes and ignores new Comments." do
    params = {
      id: 1,
      post: {
        title: "altered post",
        comments_attributes: {
          "0" => { body: "new comment" },
          "1" => { id: 1, _destroy: true },
          "2" => { id: 2, body: 'altered comment' }
        }
      }
    }

    Post.create(title: "My title1")
    Post.first.title.should == 'My title1'
    Comment.create(post_id: 1, body: "body1")
    Comment.create(post_id: 1, body: "body2")
    Comment.all.count.should == 2

    post_form = PostWithOnlyExistingCommentsForm.new(params[:post], Post.find(params[:id]))
    post_form.save
    
    comment = Comment.find_by_id(1)
    comment.should == nil

    comment = Comment.find_by_id(2)
    comment.body.should == 'altered comment'

    Comment.all.count.should == 1
    Post.first.title.should == 'altered post'

  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

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