{"action":"created","comment":{"url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/comments/26630392","id":26630392,"diff_hunk":"@@ -48,35 +46,88 @@ def upload_file!(name, ext='csv')\n     before do\n       Author.create!(name: \"John\", last_name: \"Doe\")\n       Author.create!(name: \"Jane\", last_name: \"Roe\")\n-      add_post_resource({\n-        validate: true,\n-        headers_rewrites: {\n-          :'Author Name' => :author_id\n-        },\n-        before_batch_import: ->(importer) do\n-          authors_names = importer.values_at(:author_id)\n-          # replacing author name with author id\n-          authors   = Author.where(name: authors_names).pluck(:name, :id)\n-          #{\"Jane\" => 2, \"John\" => 1}\n-          options = Hash[*authors.flatten]\n-          importer.batch_replace(:author_id, options)\n-        end\n-      })\n-      visit \"/admin/posts/import\"\n-      upload_file!(:posts)\n     end\n \n-    it \"should resolve author_id by author name\" do\n-      Post.all.each do |post|\n-        expect(Author.where(id: post.author.id)).to be_present\n+    context \"for csv for particular author\" do\n+      let(:author){ Author.take }\n+\n+      shared_examples 'successful inserts for author' do\n+        it \"should use predefined author_id\" do\n+          expect(Post.where(author_id: author.id).count).to eq(Post.count)\n+        end\n+\n+        it \"should be imported\" do\n+          expect(Post.count).to eq(2)\n+          expect(page).to have_content \"Successfully imported 2 posts\"\n+         end\n+       end\n+\n+       context \"no headers\" do\n+         before do\n+           add_post_resource(\n+             template_object: ActiveAdminImport::Model.new( { author_id: author.id , csv_headers: [:title, :body, :author_id] }),\n+             validate: true,\n+             before_batch_import: ->(importer) do\n+               importer.csv_lines.map! { |row| row << importer.model.author_id }\n+             end\n+           )\n+\n+           visit \"/admin/posts/import\"\n+           upload_file!(:posts_for_author_no_headers)\n+         end\n+         include_examples 'successful inserts for author'\n+       end\n+\n+      context \"with headers\" do\n+        before do\n+          add_post_resource(\n+            template_object: ActiveAdminImport::Model.new( { author_id: author.id }),\n+            validate: true,\n+            before_batch_import: ->(importer) do\n+              importer.csv_lines.map! { |row| row << importer.model.author_id }\n+              importer.headers.merge!({ :'Author Id' => :author_id })","path":"spec/import_spec.rb","position":89,"original_position":89,"commit_id":"f32212f31b314ed40b2e2815c0229af87bc8383c","original_commit_id":"f32212f31b314ed40b2e2815c0229af87bc8383c","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Redundant curly braces around a hash parameter.","created_at":"2015-03-18T00:46:53Z","updated_at":"2015-03-18T00:46:53Z","html_url":"https://github.com/activeadmin-plugins/active_admin_import/pull/41#discussion_r26630392","pull_request_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/41","_links":{"self":{"href":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/comments/26630392"},"html":{"href":"https://github.com/activeadmin-plugins/active_admin_import/pull/41#discussion_r26630392"},"pull_request":{"href":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/41"}}},"pull_request":{"url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/41","id":31375666,"html_url":"https://github.com/activeadmin-plugins/active_admin_import/pull/41","diff_url":"https://github.com/activeadmin-plugins/active_admin_import/pull/41.diff","patch_url":"https://github.com/activeadmin-plugins/active_admin_import/pull/41.patch","issue_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/issues/41","number":41,"state":"open","locked":false,"title":"spec for predefined foreign_key","user":{"login":"Fivell","id":120269,"avatar_url":"https://avatars.githubusercontent.com/u/120269?v=3","gravatar_id":"","url":"https://api.github.com/users/Fivell","html_url":"https://github.com/Fivell","followers_url":"https://api.github.com/users/Fivell/followers","following_url":"https://api.github.com/users/Fivell/following{/other_user}","gists_url":"https://api.github.com/users/Fivell/gists{/gist_id}","starred_url":"https://api.github.com/users/Fivell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fivell/subscriptions","organizations_url":"https://api.github.com/users/Fivell/orgs","repos_url":"https://api.github.com/users/Fivell/repos","events_url":"https://api.github.com/users/Fivell/events{/privacy}","received_events_url":"https://api.github.com/users/Fivell/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-17T20:41:03Z","updated_at":"2015-03-18T00:46:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"292db3d5c192f9918ee2651478d47aa4a019c0d7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/41/commits","review_comments_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/41/comments","review_comment_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/comments{/number}","comments_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/issues/41/comments","statuses_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/statuses/f32212f31b314ed40b2e2815c0229af87bc8383c","head":{"label":"activeadmin-plugins:import_with_particular_foreign_key","ref":"import_with_particular_foreign_key","sha":"f32212f31b314ed40b2e2815c0229af87bc8383c","user":{"login":"activeadmin-plugins","id":11481496,"avatar_url":"https://avatars.githubusercontent.com/u/11481496?v=3","gravatar_id":"","url":"https://api.github.com/users/activeadmin-plugins","html_url":"https://github.com/activeadmin-plugins","followers_url":"https://api.github.com/users/activeadmin-plugins/followers","following_url":"https://api.github.com/users/activeadmin-plugins/following{/other_user}","gists_url":"https://api.github.com/users/activeadmin-plugins/gists{/gist_id}","starred_url":"https://api.github.com/users/activeadmin-plugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/activeadmin-plugins/subscriptions","organizations_url":"https://api.github.com/users/activeadmin-plugins/orgs","repos_url":"https://api.github.com/users/activeadmin-plugins/repos","events_url":"https://api.github.com/users/activeadmin-plugins/events{/privacy}","received_events_url":"https://api.github.com/users/activeadmin-plugins/received_events","type":"Organization","site_admin":false},"repo":{"id":8607819,"name":"active_admin_import","full_name":"activeadmin-plugins/active_admin_import","owner":{"login":"activeadmin-plugins","id":11481496,"avatar_url":"https://avatars.githubusercontent.com/u/11481496?v=3","gravatar_id":"","url":"https://api.github.com/users/activeadmin-plugins","html_url":"https://github.com/activeadmin-plugins","followers_url":"https://api.github.com/users/activeadmin-plugins/followers","following_url":"https://api.github.com/users/activeadmin-plugins/following{/other_user}","gists_url":"https://api.github.com/users/activeadmin-plugins/gists{/gist_id}","starred_url":"https://api.github.com/users/activeadmin-plugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/activeadmin-plugins/subscriptions","organizations_url":"https://api.github.com/users/activeadmin-plugins/orgs","repos_url":"https://api.github.com/users/activeadmin-plugins/repos","events_url":"https://api.github.com/users/activeadmin-plugins/events{/privacy}","received_events_url":"https://api.github.com/users/activeadmin-plugins/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/activeadmin-plugins/active_admin_import","description":"active_admin_import is based on activerecord-import gem  - the most efficient way to import for ActiveAdmin","fork":false,"url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import","forks_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/forks","keys_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/keys{/key_id}","collaborators_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/teams","hooks_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/hooks","issue_events_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/issues/events{/number}","events_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/events","assignees_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/assignees{/user}","branches_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/branches{/branch}","tags_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/tags","blobs_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/git/refs{/sha}","trees_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/git/trees{/sha}","statuses_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/statuses/{sha}","languages_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/languages","stargazers_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/stargazers","contributors_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/contributors","subscribers_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/subscribers","subscription_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/subscription","commits_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/commits{/sha}","git_commits_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/git/commits{/sha}","comments_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/comments{/number}","issue_comment_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/issues/comments{/number}","contents_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/contents/{+path}","compare_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/compare/{base}...{head}","merges_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/merges","archive_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/downloads","issues_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/issues{/number}","pulls_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls{/number}","milestones_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/milestones{/number}","notifications_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/labels{/name}","releases_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/releases{/id}","created_at":"2013-03-06T16:33:45Z","updated_at":"2015-03-15T00:14:43Z","pushed_at":"2015-03-18T00:46:46Z","git_url":"git://github.com/activeadmin-plugins/active_admin_import.git","ssh_url":"git@github.com:activeadmin-plugins/active_admin_import.git","clone_url":"https://github.com/activeadmin-plugins/active_admin_import.git","svn_url":"https://github.com/activeadmin-plugins/active_admin_import","homepage":"http://fivell.github.io/active_admin_import","size":1211,"stargazers_count":34,"watchers_count":34,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":20,"mirror_url":null,"open_issues_count":2,"forks":20,"open_issues":2,"watchers":34,"default_branch":"master"}},"base":{"label":"activeadmin-plugins:master","ref":"master","sha":"cb44dc235884c554679872a875564670e526fc1d","user":{"login":"activeadmin-plugins","id":11481496,"avatar_url":"https://avatars.githubusercontent.com/u/11481496?v=3","gravatar_id":"","url":"https://api.github.com/users/activeadmin-plugins","html_url":"https://github.com/activeadmin-plugins","followers_url":"https://api.github.com/users/activeadmin-plugins/followers","following_url":"https://api.github.com/users/activeadmin-plugins/following{/other_user}","gists_url":"https://api.github.com/users/activeadmin-plugins/gists{/gist_id}","starred_url":"https://api.github.com/users/activeadmin-plugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/activeadmin-plugins/subscriptions","organizations_url":"https://api.github.com/users/activeadmin-plugins/orgs","repos_url":"https://api.github.com/users/activeadmin-plugins/repos","events_url":"https://api.github.com/users/activeadmin-plugins/events{/privacy}","received_events_url":"https://api.github.com/users/activeadmin-plugins/received_events","type":"Organization","site_admin":false},"repo":{"id":8607819,"name":"active_admin_import","full_name":"activeadmin-plugins/active_admin_import","owner":{"login":"activeadmin-plugins","id":11481496,"avatar_url":"https://avatars.githubusercontent.com/u/11481496?v=3","gravatar_id":"","url":"https://api.github.com/users/activeadmin-plugins","html_url":"https://github.com/activeadmin-plugins","followers_url":"https://api.github.com/users/activeadmin-plugins/followers","following_url":"https://api.github.com/users/activeadmin-plugins/following{/other_user}","gists_url":"https://api.github.com/users/activeadmin-plugins/gists{/gist_id}","starred_url":"https://api.github.com/users/activeadmin-plugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/activeadmin-plugins/subscriptions","organizations_url":"https://api.github.com/users/activeadmin-plugins/orgs","repos_url":"https://api.github.com/users/activeadmin-plugins/repos","events_url":"https://api.github.com/users/activeadmin-plugins/events{/privacy}","received_events_url":"https://api.github.com/users/activeadmin-plugins/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/activeadmin-plugins/active_admin_import","description":"active_admin_import is based on activerecord-import gem  - the most efficient way to import for ActiveAdmin","fork":false,"url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import","forks_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/forks","keys_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/keys{/key_id}","collaborators_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/teams","hooks_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/hooks","issue_events_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/issues/events{/number}","events_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/events","assignees_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/assignees{/user}","branches_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/branches{/branch}","tags_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/tags","blobs_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/git/refs{/sha}","trees_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/git/trees{/sha}","statuses_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/statuses/{sha}","languages_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/languages","stargazers_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/stargazers","contributors_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/contributors","subscribers_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/subscribers","subscription_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/subscription","commits_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/commits{/sha}","git_commits_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/git/commits{/sha}","comments_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/comments{/number}","issue_comment_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/issues/comments{/number}","contents_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/contents/{+path}","compare_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/compare/{base}...{head}","merges_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/merges","archive_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/downloads","issues_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/issues{/number}","pulls_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls{/number}","milestones_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/milestones{/number}","notifications_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/labels{/name}","releases_url":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/releases{/id}","created_at":"2013-03-06T16:33:45Z","updated_at":"2015-03-15T00:14:43Z","pushed_at":"2015-03-18T00:46:46Z","git_url":"git://github.com/activeadmin-plugins/active_admin_import.git","ssh_url":"git@github.com:activeadmin-plugins/active_admin_import.git","clone_url":"https://github.com/activeadmin-plugins/active_admin_import.git","svn_url":"https://github.com/activeadmin-plugins/active_admin_import","homepage":"http://fivell.github.io/active_admin_import","size":1211,"stargazers_count":34,"watchers_count":34,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":20,"mirror_url":null,"open_issues_count":2,"forks":20,"open_issues":2,"watchers":34,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/41"},"html":{"href":"https://github.com/activeadmin-plugins/active_admin_import/pull/41"},"issue":{"href":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/issues/41"},"comments":{"href":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/issues/41/comments"},"review_comments":{"href":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/41/comments"},"review_comment":{"href":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/pulls/41/commits"},"statuses":{"href":"https://api.github.com/repos/activeadmin-plugins/active_admin_import/statuses/f32212f31b314ed40b2e2815c0229af87bc8383c"}}}}