Commit ef8f348c by Greg Price

Clean databases between rspec tests

parent 62b7ab50
......@@ -48,6 +48,7 @@ group :test do
gem 'guard'
gem 'guard-unicorn'
gem 'simplecov', :require => false
gem 'database_cleaner'
end
gem 'newrelic_rpm'
......
......@@ -63,6 +63,7 @@ GEM
builder (3.0.4)
coderay (1.0.7)
dalli (2.1.0)
database_cleaner (1.2.0)
delayed_job (3.0.3)
activesupport (~> 3.0)
diff-lcs (1.1.3)
......@@ -166,6 +167,7 @@ DEPENDENCIES
bson_ext
bundler
dalli
database_cleaner
delayed_job
delayed_job_mongoid!
faker
......
......@@ -450,6 +450,7 @@ describe "app" do
end
end
describe "DELETE /api/v1/threads/:thread_id" do
before(:each) { init_without_subscriptions }
it "delete the comment thread and its comments" do
thread = CommentThread.first.to_hash
delete "/api/v1/threads/#{thread['id']}"
......
require 'spec_helper'
describe "app" do
let(:author) { create_test_user(1) }
describe "thread search" do
describe "GET /api/v1/search/threads" do
it "returns thread with query match" do
user = User.find 1
if user.nil?
user = create_test_user(1)
end
commentable = Commentable.new("question_1")
random_string = (0...8).map{ ('a'..'z').to_a[rand(26)] }.join
thread = CommentThread.new(title: "Test title", body: random_string, course_id: "1", commentable_id: commentable.id)
thread.author = user
thread.author = author
thread.save!
sleep 3
......@@ -31,23 +27,18 @@ describe "app" do
describe "comment search" do
describe "GET /api/v1/search/threads" do
it "returns thread with comment query match" do
user = User.find 1
if user.nil?
user = create_test_user(1)
end
commentable = Commentable.new("question_1")
random_string = (0...8).map{ ('a'..'z').to_a[rand(26)] }.join
thread = CommentThread.new(title: "Test title", body: "elephant otter", course_id: "1", commentable_id: commentable.id)
thread.author = user
thread.author = author
thread.save!
sleep 3
comment = Comment.new(body: random_string, course_id: "1", commentable_id: commentable.id)
comment.author = user
comment.author = author
comment.comment_thread = thread
comment.save!
......
......@@ -7,6 +7,7 @@ require File.join(File.dirname(__FILE__), '..', 'app')
require 'sinatra'
require 'rack/test'
require 'yajl'
require 'database_cleaner'
# setup test environment
set :environment, :test
......@@ -25,7 +26,14 @@ RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run focus: true
config.run_all_when_everything_filtered = true
config.before(:each) { Mongoid::IdentityMap.clear }
config.before(:each) do
Mongoid::IdentityMap.clear
DatabaseCleaner.clean
[CommentThread, Comment].each do |class_|
class_.tire.index.delete
class_.create_elasticsearch_index
end
end
end
Mongoid.configure do |config|
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment