Permalink
Browse files

Add in some actual tests

  • Loading branch information...
Sutto committed Dec 24, 2010
1 parent 09bcca8 commit 2890395af37be3d11fc287b8cbca8ba6059b5059
View
@@ -44,5 +44,5 @@ rescue LoadError
end
end
-task :test => :check_dependencies
+task :test
task :default => :test
@@ -0,0 +1,21 @@
+require 'helper'
+
+class AlmostHappy::TestActiveRecordMixin < Test::Unit::TestCase
+
+ context 'adding class methods' do
+
+ should 'add the is_convertable method' do
+ assert ActiveRecord::Base.respond_to?(:is_convertable)
+ end
+
+ should 'add the is_publishable method' do
+ assert ActiveRecord::Base.respond_to?(:is_publishable)
+ end
+
+ end
+
+ should 'automatically add itself to activerecord' do
+ assert(ActiveRecord::Base < AlmostHappy::ActiveRecordMixin, 'AR::Base has the mixin')
+ end
+
+end
@@ -0,0 +1,7 @@
+require 'helper'
+
+class AlmostHappy::TestConvertable < Test::Unit::TestCase
+ should "probably rename this file and start testing for real" do
+ flunk "hey buddy, you should probably rename this file and start testing for real"
+ end
+end
@@ -0,0 +1,7 @@
+require 'helper'
+
+class AlmostHappy::TestConvertor < Test::Unit::TestCase
+ should "probably rename this file and start testing for real" do
+ flunk "hey buddy, you should probably rename this file and start testing for real"
+ end
+end
@@ -0,0 +1,7 @@
+require 'helper'
+
+class AlmostHappy::TestFormatValidator < Test::Unit::TestCase
+ should "probably rename this file and start testing for real" do
+ flunk "hey buddy, you should probably rename this file and start testing for real"
+ end
+end
@@ -0,0 +1,7 @@
+require 'helper'
+
+class AlmostHappy::TestPublishable < Test::Unit::TestCase
+ should "probably rename this file and start testing for real" do
+ flunk "hey buddy, you should probably rename this file and start testing for real"
+ end
+end
@@ -0,0 +1,82 @@
+require 'helper'
+
+class AlmostHappy::TestScopeable < Test::Unit::TestCase
+ with_tables :publishable do
+
+ should 'by default not be included' do
+ assert !(Publishable < AlmostHappy::Scopeable)
+ end
+
+ should 'be added by is_publishable' do
+ Publishable.is_publishable
+ assert Publishable < AlmostHappy::Scopeable
+ end
+
+ context 'with a publishable model' do
+
+ setup { Publishable.is_publishable }
+
+ should 'add a published relationship method' do
+ assert Publishable.respond_to?(:published)
+ end
+
+ should 'add a unpublished relationship method' do
+ assert Publishable.respond_to?(:unpublished)
+ end
+
+ should 'add a ordered relationship method' do
+ assert Publishable.respond_to?(:ordered)
+ end
+
+ should 'add a ordered_for_preview relationship method' do
+ assert Publishable.respond_to?(:ordered_for_preview)
+ end
+
+ should 'return a relationship from published' do
+ assert Publishable.published.is_a?(ActiveRecord::Relation)
+ end
+
+ should 'return a relationship from unpublished' do
+ assert Publishable.unpublished.is_a?(ActiveRecord::Relation)
+ end
+
+ should 'return a relationship from ordered' do
+ assert Publishable.ordered.is_a?(ActiveRecord::Relation)
+ end
+
+ should 'return a relationship from ordered_for_preview' do
+ assert Publishable.ordered_for_preview.is_a?(ActiveRecord::Relation)
+ end
+
+ context 'with published items do' do
+
+ setup do
+ @published_a = Publishable.create!(:published_at => 3.weeks.ago)
+ @published_b = Publishable.create!(:published_at => 1.day.ago)
+ @unpublished_a = Publishable.create!(:published_at => 3.weeks.from_now)
+ @unpublished_b = Publishable.create!(:published_at => 2.hours.from_now)
+ @unpublished_c = Publishable.create!(:published_at => nil)
+ end
+
+ should 'return the correct items for published' do
+ assert_same_elements [@published_a, @published_b], Publishable.published.all
+ end
+
+ should 'return the correct items for unpublished' do
+ assert_same_elements [@unpublished_a, @unpublished_b, @unpublished_c], Publishable.unpublished.all
+ end
+
+ should 'have the correct order for ordered' do
+ assert_equal [@unpublished_a, @unpublished_b, @published_b, @published_a, @unpublished_c], Publishable.ordered.all
+ end
+
+ should 'have the correct order for ordered_for_preview' do
+ assert_equal [@unpublished_c, @unpublished_a, @unpublished_b, @published_b, @published_a], Publishable.ordered_for_preview.all
+ end
+
+ end
+
+ end
+
+ end
+end
View
@@ -1,10 +1,21 @@
+$KCODE = 'UTF8'
+
require 'rubygems'
+
require 'test/unit'
require 'shoulda'
+require 'rr'
+require 'redgreen' if RUBY_VERSION < '1.9'
+require 'ruby-debug' if ENV['DEBUG']
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
+
+require 'active_record'
require 'almost-happy'
+require 'model_definitions'
class Test::Unit::TestCase
+ include RR::Adapters::TestUnit
+ extend ReversibleData::ShouldaMacros
end
View
@@ -0,0 +1,25 @@
+require 'reversible_data'
+
+ReversibleData.in_memory!
+
+ReversibleData.add :publishable do |p|
+ p.datetime :published_at
+end
+
+ReversibleData.add :simple_convertable do |sc|
+ sc.text :description
+ sc.text :rendered_description
+end
+
+ReversibleData.add :simple_convertable_with_format do |sc|
+ sc.text :description
+ sc.text :rendered_description
+ sc.string :format
+end
+
+ReversibleData.add :multiple_convertable do |mc|
+ mc.text :description
+ mc.text :rendered_description
+ mc.text :profile
+ mc.text :rendered_profile
+end

0 comments on commit 2890395

Please sign in to comment.