{"action":"created","comment":{"url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/comments/59120147","id":59120147,"diff_hunk":"@@ -0,0 +1,119 @@\n+---\n+layout: post\n+title: Database Cleaner with RSpec\n+category: code\n+description: \"Setting up Database Cleaner with RSpec\"\n+---\n+\n+When writing tests for a Rails application there is a good chance you will need\n+to create records in the database. To have reliable tests those records should\n+be removed after every run. This is a painful process to do manually. However\n+there is a library that handles cleaning up your database after every run.\n+\n+Setting up [database_cleaner](https://github.com/DatabaseCleaner/database_cleaner)\n+can be a little tricky, especially if you are not using ActiveRecord.\n+\n+## Installation and Basic Setup\n+\n+Add the database_cleaner gem to your Gemfile:\n+\n+~~~ruby\n+group :test do\n+  gem \"database_cleaner\"\n+end\n+~~~\n+\n+The next step is configuring the database cleaner gem for your ORM. In the case of\n+ActiveRecord and the transaction strategy the configuration below is all you need.\n+Add the following to `spec/rails_helper.rb`\n+\n+~~~ ruby\n+RSpec.configure do |config|\n+  config.use_transactional_fixtures = false\n+\n+  config.before(:suite) do\n+    DatabaseCleaner.strategy = :transaction\n+    DatabaseCleaner.clean_with(:truncation)\n+  end\n+\n+  config.around(:each) do |example|\n+    DatabaseCleaner.cleaning do\n+      example.run\n+    end\n+  end\n+end\n+~~~\n+\n+Database cleaner comes with several strategies for cleaning your database after\n+creating records. For SQL libraries the fastest strategy will be transaction","path":"_posts/code/rspec/2016-04-09-database-cleaner-setup.md","position":48,"original_position":48,"commit_id":"413f76b8b22889c3b3fbdf151132b44a7bacb82e","original_commit_id":"413f76b8b22889c3b3fbdf151132b44a7bacb82e","user":{"login":"mcasper","id":6878025,"avatar_url":"https://avatars.githubusercontent.com/u/6878025?v=3","gravatar_id":"","url":"https://api.github.com/users/mcasper","html_url":"https://github.com/mcasper","followers_url":"https://api.github.com/users/mcasper/followers","following_url":"https://api.github.com/users/mcasper/following{/other_user}","gists_url":"https://api.github.com/users/mcasper/gists{/gist_id}","starred_url":"https://api.github.com/users/mcasper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcasper/subscriptions","organizations_url":"https://api.github.com/users/mcasper/orgs","repos_url":"https://api.github.com/users/mcasper/repos","events_url":"https://api.github.com/users/mcasper/events{/privacy}","received_events_url":"https://api.github.com/users/mcasper/received_events","type":"User","site_admin":false},"body":"Should this be `SQL databases`?","created_at":"2016-04-09T19:32:32Z","updated_at":"2016-04-09T19:32:32Z","html_url":"https://github.com/mildlyinternet/mildlyinternet.github.io/pull/3#discussion_r59120147","pull_request_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/comments/59120147"},"html":{"href":"https://github.com/mildlyinternet/mildlyinternet.github.io/pull/3#discussion_r59120147"},"pull_request":{"href":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/3","id":65889664,"html_url":"https://github.com/mildlyinternet/mildlyinternet.github.io/pull/3","diff_url":"https://github.com/mildlyinternet/mildlyinternet.github.io/pull/3.diff","patch_url":"https://github.com/mildlyinternet/mildlyinternet.github.io/pull/3.patch","issue_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/issues/3","number":3,"state":"open","locked":false,"title":"Setting up database_cleaner in RSpec","user":{"login":"mikeastock","id":1907044,"avatar_url":"https://avatars.githubusercontent.com/u/1907044?v=3","gravatar_id":"","url":"https://api.github.com/users/mikeastock","html_url":"https://github.com/mikeastock","followers_url":"https://api.github.com/users/mikeastock/followers","following_url":"https://api.github.com/users/mikeastock/following{/other_user}","gists_url":"https://api.github.com/users/mikeastock/gists{/gist_id}","starred_url":"https://api.github.com/users/mikeastock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikeastock/subscriptions","organizations_url":"https://api.github.com/users/mikeastock/orgs","repos_url":"https://api.github.com/users/mikeastock/repos","events_url":"https://api.github.com/users/mikeastock/events{/privacy}","received_events_url":"https://api.github.com/users/mikeastock/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-04-09T19:14:52Z","updated_at":"2016-04-09T19:32:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"29430ffefce35373f96a606f149080f67c3a2061","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/3/commits","review_comments_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/3/comments","review_comment_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/issues/3/comments","statuses_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/statuses/413f76b8b22889c3b3fbdf151132b44a7bacb82e","head":{"label":"mildlyinternet:rspec/database-cleaner","ref":"rspec/database-cleaner","sha":"413f76b8b22889c3b3fbdf151132b44a7bacb82e","user":{"login":"mildlyinternet","id":18368473,"avatar_url":"https://avatars.githubusercontent.com/u/18368473?v=3","gravatar_id":"","url":"https://api.github.com/users/mildlyinternet","html_url":"https://github.com/mildlyinternet","followers_url":"https://api.github.com/users/mildlyinternet/followers","following_url":"https://api.github.com/users/mildlyinternet/following{/other_user}","gists_url":"https://api.github.com/users/mildlyinternet/gists{/gist_id}","starred_url":"https://api.github.com/users/mildlyinternet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mildlyinternet/subscriptions","organizations_url":"https://api.github.com/users/mildlyinternet/orgs","repos_url":"https://api.github.com/users/mildlyinternet/repos","events_url":"https://api.github.com/users/mildlyinternet/events{/privacy}","received_events_url":"https://api.github.com/users/mildlyinternet/received_events","type":"Organization","site_admin":false},"repo":{"id":55857489,"name":"mildlyinternet.github.io","full_name":"mildlyinternet/mildlyinternet.github.io","owner":{"login":"mildlyinternet","id":18368473,"avatar_url":"https://avatars.githubusercontent.com/u/18368473?v=3","gravatar_id":"","url":"https://api.github.com/users/mildlyinternet","html_url":"https://github.com/mildlyinternet","followers_url":"https://api.github.com/users/mildlyinternet/followers","following_url":"https://api.github.com/users/mildlyinternet/following{/other_user}","gists_url":"https://api.github.com/users/mildlyinternet/gists{/gist_id}","starred_url":"https://api.github.com/users/mildlyinternet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mildlyinternet/subscriptions","organizations_url":"https://api.github.com/users/mildlyinternet/orgs","repos_url":"https://api.github.com/users/mildlyinternet/repos","events_url":"https://api.github.com/users/mildlyinternet/events{/privacy}","received_events_url":"https://api.github.com/users/mildlyinternet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mildlyinternet/mildlyinternet.github.io","description":"Mildly Internet Blog","fork":false,"url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io","forks_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/forks","keys_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/teams","hooks_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/hooks","issue_events_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/issues/events{/number}","events_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/events","assignees_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/assignees{/user}","branches_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/branches{/branch}","tags_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/tags","blobs_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/statuses/{sha}","languages_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/languages","stargazers_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/stargazers","contributors_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/contributors","subscribers_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/subscribers","subscription_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/subscription","commits_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/contents/{+path}","compare_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/merges","archive_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/downloads","issues_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/issues{/number}","pulls_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls{/number}","milestones_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/milestones{/number}","notifications_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/labels{/name}","releases_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/releases{/id}","deployments_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/deployments","created_at":"2016-04-09T17:24:01Z","updated_at":"2016-04-09T17:29:26Z","pushed_at":"2016-04-09T19:26:48Z","git_url":"git://github.com/mildlyinternet/mildlyinternet.github.io.git","ssh_url":"git@github.com:mildlyinternet/mildlyinternet.github.io.git","clone_url":"https://github.com/mildlyinternet/mildlyinternet.github.io.git","svn_url":"https://github.com/mildlyinternet/mildlyinternet.github.io","homepage":"https://mildlyinternet.github.io","size":16465,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"mildlyinternet:master","ref":"master","sha":"8b5fd6ac7550c6919d69c9b799650092e53e6666","user":{"login":"mildlyinternet","id":18368473,"avatar_url":"https://avatars.githubusercontent.com/u/18368473?v=3","gravatar_id":"","url":"https://api.github.com/users/mildlyinternet","html_url":"https://github.com/mildlyinternet","followers_url":"https://api.github.com/users/mildlyinternet/followers","following_url":"https://api.github.com/users/mildlyinternet/following{/other_user}","gists_url":"https://api.github.com/users/mildlyinternet/gists{/gist_id}","starred_url":"https://api.github.com/users/mildlyinternet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mildlyinternet/subscriptions","organizations_url":"https://api.github.com/users/mildlyinternet/orgs","repos_url":"https://api.github.com/users/mildlyinternet/repos","events_url":"https://api.github.com/users/mildlyinternet/events{/privacy}","received_events_url":"https://api.github.com/users/mildlyinternet/received_events","type":"Organization","site_admin":false},"repo":{"id":55857489,"name":"mildlyinternet.github.io","full_name":"mildlyinternet/mildlyinternet.github.io","owner":{"login":"mildlyinternet","id":18368473,"avatar_url":"https://avatars.githubusercontent.com/u/18368473?v=3","gravatar_id":"","url":"https://api.github.com/users/mildlyinternet","html_url":"https://github.com/mildlyinternet","followers_url":"https://api.github.com/users/mildlyinternet/followers","following_url":"https://api.github.com/users/mildlyinternet/following{/other_user}","gists_url":"https://api.github.com/users/mildlyinternet/gists{/gist_id}","starred_url":"https://api.github.com/users/mildlyinternet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mildlyinternet/subscriptions","organizations_url":"https://api.github.com/users/mildlyinternet/orgs","repos_url":"https://api.github.com/users/mildlyinternet/repos","events_url":"https://api.github.com/users/mildlyinternet/events{/privacy}","received_events_url":"https://api.github.com/users/mildlyinternet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mildlyinternet/mildlyinternet.github.io","description":"Mildly Internet Blog","fork":false,"url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io","forks_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/forks","keys_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/teams","hooks_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/hooks","issue_events_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/issues/events{/number}","events_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/events","assignees_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/assignees{/user}","branches_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/branches{/branch}","tags_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/tags","blobs_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/git/refs{/sha}","trees_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/statuses/{sha}","languages_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/languages","stargazers_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/stargazers","contributors_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/contributors","subscribers_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/subscribers","subscription_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/subscription","commits_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/commits{/sha}","git_commits_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/git/commits{/sha}","comments_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/comments{/number}","issue_comment_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/issues/comments{/number}","contents_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/contents/{+path}","compare_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/merges","archive_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/downloads","issues_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/issues{/number}","pulls_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls{/number}","milestones_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/milestones{/number}","notifications_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/labels{/name}","releases_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/releases{/id}","deployments_url":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/deployments","created_at":"2016-04-09T17:24:01Z","updated_at":"2016-04-09T17:29:26Z","pushed_at":"2016-04-09T19:26:48Z","git_url":"git://github.com/mildlyinternet/mildlyinternet.github.io.git","ssh_url":"git@github.com:mildlyinternet/mildlyinternet.github.io.git","clone_url":"https://github.com/mildlyinternet/mildlyinternet.github.io.git","svn_url":"https://github.com/mildlyinternet/mildlyinternet.github.io","homepage":"https://mildlyinternet.github.io","size":16465,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/3"},"html":{"href":"https://github.com/mildlyinternet/mildlyinternet.github.io/pull/3"},"issue":{"href":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/issues/3"},"comments":{"href":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/mildlyinternet/mildlyinternet.github.io/statuses/413f76b8b22889c3b3fbdf151132b44a7bacb82e"}}}}