title: RSpec: Cannot add or update a child row: a foreign key constraint fails
body: <p>I'm tackling RSpec error.
  Article associates ArticlesArticleSeries. Also ArticlesArticleSeries associates ArticleSeries.
  ArticlesArticleSeries has two fk constraint. So the problem occurs when inserting record without ArticleSeries association.</p>
  
  <p>Does anybody know how to fix it?</p>
  
  <pre><code>  1) ArticlesController GET #index assigns all article
       Failure/Error: article = Article.create! valid_attributes
  
       ActiveRecord::InvalidForeignKey:
         Mysql2::Error: Cannot add or update a child row: a foreign key constraint fails (`eiicon`.`articles_article_series`, CONSTRAINT `articles_article_series_ibfk_2` FOREIGN KEY (`series_id`) REFERENCES `article_series` (`id`)): INSERT INTO `articles_article_series` (`article_id`, `series_id`, `num`) VALUES (1, 2, 3)
       # ./spec/controllers/articles_controller_spec.rb:60:in `block (3 levels) in &lt;top (required)&gt;'
       # ------------------
       # --- Caused by: ---
       # Mysql2::Error:
       #   Cannot add or update a child row: a foreign key constraint fails (`eiicon`.`articles_article_series`, CONSTRAINT `articles_article_series_ibfk_2` FOREIGN KEY (`series_id`) REFERENCES `article_series` (`id`))
       #   ./spec/controllers/articles_controller_spec.rb:60:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <p>My RSpec code is here</p>
  
  <pre><code>  let(:valid_attributes) {
      {
        id: 1,
        current_version: 1,
        publish_version: 1,
        thumbnail: "uploads/article/thumb/thumb_20170327055055.png",
        status: "publish",
        publish_datetime: "2017-04-16 19:51:03",
        user_id: 1,
        update_user_id: 1,
        article_histories_attributes:[
          version: 1,
          title: "Hello!",
          content: "World!World!!!"
        ],
        articles_article_series_attributes: valid_series_attributes
      }
    }
    let(:valid_series_attributes) {
      {
        article_id: 1,
        series_id: 2,
        num: 3
      }
    }
    let(:valid_aseries_attributes) {
      {
        id: 1, name: "test"
      }
    }
  
        it 'assigns the article as @article' do
          article_series = ArticleSeries.create! valid_aseries_attributes
          article = Article.create! valid_attributes
          put :update, params: {article: new_article_attributes.merge(new_series_attributes), article_histories: new_history_attributes}, session: valid_session
          expect(assigns(:article)).to eq(article)
        end
  </code></pre>