tests: add more post/pool version creation tests.

Adds the `test_after_commit` gem too because after_commit callbacks
don't fire inside tests in rails <5.0.
This commit is contained in:
evazion 2017-04-01 03:32:02 -05:00 committed by r888888888
parent 8fff3315f2
commit 3c89ee3199
4 changed files with 57 additions and 2 deletions

View File

@ -73,4 +73,5 @@ group :test do
gem "simplecov", :require => false
gem "timecop"
gem "fakeweb"
gem "test_after_commit" # XXX remove me after upgrading to rails 5.
end

View File

@ -326,6 +326,8 @@ GEM
rest-client (~> 1.4)
term-ansicolor (1.3.2)
tins (~> 1.0)
test_after_commit (1.1.0)
activerecord (>= 3.2)
therubyracer (0.12.3)
libv8 (~> 3.16.14.15)
ref
@ -422,6 +424,7 @@ DEPENDENCIES
streamio-ffmpeg
stripe
term-ansicolor
test_after_commit
therubyracer
timecop
twitter
@ -432,4 +435,4 @@ DEPENDENCIES
whenever
BUNDLED WITH
1.14.5
1.14.6

View File

@ -238,6 +238,20 @@ class PoolTest < ActiveSupport::TestCase
assert_equal(2, @pool.versions.size)
end
should "not create a version if updating the pool fails" do
@pool.stubs(:synchronize!).raises(NotImplementedError)
assert_raise(NotImplementedError) { @pool.update(name: "blah") }
assert_equal(1, @pool.versions.size)
end
should "should create a version if the name changes" do
assert_difference("@pool.versions.size", 1) do
@pool.update(name: "blah")
assert_equal("blah", @pool.versions.last.name)
end
end
should "know what its post ids were previously" do
@pool.post_ids = "#{@p1.id}"
assert_equal("", @pool.post_ids_was)

View File

@ -87,10 +87,11 @@ class PostArchiveTest < ActiveSupport::TestCase
setup do
PostArchive.sqs_service.stubs(:merge?).returns(false)
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")
end
should "also create a version" do
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")
assert_equal(2, @post.versions.size)
@version = @post.versions.last
assert_equal("bbb ccc xxx", @version.tags)
@ -98,6 +99,42 @@ class PostArchiveTest < ActiveSupport::TestCase
assert_equal("", @version.source)
assert_nil(@version.parent_id)
end
should "not create a version if updating the post fails" do
@post.stubs(:apply_post_metatags).raises(NotImplementedError)
assert_raise(NotImplementedError) { @post.update(rating: "s") }
assert_equal(1, @post.versions.size)
end
should "should create a version if the rating changes" do
assert_difference("@post.versions.size", 1) do
@post.update(rating: "s")
assert_equal("s", @post.versions.last.rating)
end
end
should "should create a version if the source changes" do
assert_difference("@post.versions.size", 1) do
@post.update(source: "blah")
assert_equal("blah", @post.versions.last.source)
end
end
should "should create a version if the parent changes" do
assert_difference("@post.versions.size", 1) do
@parent = FactoryGirl.create(:post)
@post.update(parent_id: @parent.id)
assert_equal(@parent.id, @post.versions.last.parent_id)
end
end
should "should create a version if the tags change" do
assert_difference("@post.versions.size", 1) do
@post.update(tag_string: "blah")
assert_equal("blah", @post.versions.last.tags)
end
end
end
end
end