/example-post

Demonstrating a potential issue with Rails

Primary LanguageRuby

README

The purpose of this repo is to demonstrate an issue with Rails and using accepts_nested_attributes_for. Reproduction steps by running the following:

  1. Run: ruby lib/rails-bug-report.rb - This file is an executable test case from Rails. The test will pass

Now proceed to run the following:

  1. bundle install
  2. rake db:migrate
  3. rails c
  4. Paste the following:
author_params = {
  first_name: 'Joe',
  last_name: 'Bloggs',
  bio: 'Foo',
  posts_attributes: [{title: 'Cool', body: 'Beans'}]
}
Author.create(author_params)

You'll find that upon running: Author.create(author_params) it won't persist the record. The expectation should be that the Author & Post records are persisted (per rails-bug-report.rb expectation). Making things more interesting you'll find that if you run rails test the test fail. Whereas if you run: ruby lib/rails-bug-report.rb which contains the exact same tests the pass.