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:
1
Gemfile
1
Gemfile
@@ -73,4 +73,5 @@ group :test do
|
|||||||
gem "simplecov", :require => false
|
gem "simplecov", :require => false
|
||||||
gem "timecop"
|
gem "timecop"
|
||||||
gem "fakeweb"
|
gem "fakeweb"
|
||||||
|
gem "test_after_commit" # XXX remove me after upgrading to rails 5.
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -326,6 +326,8 @@ GEM
|
|||||||
rest-client (~> 1.4)
|
rest-client (~> 1.4)
|
||||||
term-ansicolor (1.3.2)
|
term-ansicolor (1.3.2)
|
||||||
tins (~> 1.0)
|
tins (~> 1.0)
|
||||||
|
test_after_commit (1.1.0)
|
||||||
|
activerecord (>= 3.2)
|
||||||
therubyracer (0.12.3)
|
therubyracer (0.12.3)
|
||||||
libv8 (~> 3.16.14.15)
|
libv8 (~> 3.16.14.15)
|
||||||
ref
|
ref
|
||||||
@@ -422,6 +424,7 @@ DEPENDENCIES
|
|||||||
streamio-ffmpeg
|
streamio-ffmpeg
|
||||||
stripe
|
stripe
|
||||||
term-ansicolor
|
term-ansicolor
|
||||||
|
test_after_commit
|
||||||
therubyracer
|
therubyracer
|
||||||
timecop
|
timecop
|
||||||
twitter
|
twitter
|
||||||
@@ -432,4 +435,4 @@ DEPENDENCIES
|
|||||||
whenever
|
whenever
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.14.5
|
1.14.6
|
||||||
|
|||||||
@@ -238,6 +238,20 @@ class PoolTest < ActiveSupport::TestCase
|
|||||||
assert_equal(2, @pool.versions.size)
|
assert_equal(2, @pool.versions.size)
|
||||||
end
|
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
|
should "know what its post ids were previously" do
|
||||||
@pool.post_ids = "#{@p1.id}"
|
@pool.post_ids = "#{@p1.id}"
|
||||||
assert_equal("", @pool.post_ids_was)
|
assert_equal("", @pool.post_ids_was)
|
||||||
|
|||||||
@@ -87,10 +87,11 @@ class PostArchiveTest < ActiveSupport::TestCase
|
|||||||
setup do
|
setup do
|
||||||
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
PostArchive.sqs_service.stubs(:merge?).returns(false)
|
||||||
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
@post = FactoryGirl.create(:post, :tag_string => "aaa bbb ccc", :rating => "q", :source => "xyz")
|
||||||
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "also create a version" do
|
should "also create a version" do
|
||||||
|
@post.update_attributes(:tag_string => "bbb ccc xxx", :source => "")
|
||||||
|
|
||||||
assert_equal(2, @post.versions.size)
|
assert_equal(2, @post.versions.size)
|
||||||
@version = @post.versions.last
|
@version = @post.versions.last
|
||||||
assert_equal("bbb ccc xxx", @version.tags)
|
assert_equal("bbb ccc xxx", @version.tags)
|
||||||
@@ -98,6 +99,42 @@ class PostArchiveTest < ActiveSupport::TestCase
|
|||||||
assert_equal("", @version.source)
|
assert_equal("", @version.source)
|
||||||
assert_nil(@version.parent_id)
|
assert_nil(@version.parent_id)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user