Skip to content

Commit

Permalink
unit tests for carousel
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg committed Feb 6, 2012
1 parent 5fa64d5 commit a9597c3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
33 changes: 28 additions & 5 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,34 @@
require 'rails/test_help'

class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
#
# Note: You'll currently still have to declare fixtures explicitly in integration tests
# -- they do not yet inherit this setting

fixtures :all

def setup
reset_config
end

# resetting default configuration
def reset_config
ComfyCarousel.configure do |config|
config.admin_route_prefix = 'admin'
config.admin_controller = 'ApplicationController'
config.form_builder = 'ComfyBlog::FormBuilder'
end
end

# Add more helper methods to be used by all tests here...
# Example usage:
# assert_has_errors_on( @record, [:field_1, :field_2] )
# assert_has_errors_on( @record, {:field_1 => 'Message1', :field_2 => 'Message 2'} )
def assert_has_errors_on(record, fields)
fields = [fields].flatten unless fields.is_a?(Hash)
fields.each do |field, message|
assert record.errors.to_hash.has_key?(field.to_sym), "#{record.class.name} should error on invalid #{field}"
if message && record.errors[field].is_a?(Array) && !message.is_a?(Array)
assert_not_nil record.errors[field].index(message)
elsif message
assert_equal message, record.errors[field]
end
end
end
end
17 changes: 13 additions & 4 deletions test/unit/carousel_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@
class CarouselTest < ActiveSupport::TestCase

def test_fixtures_validity

Carousel::Carousel.all.each do |carousel|
assert carousel.valid?, carousel.errors.inspect
end
end

def test_validations

carousel = Carousel::Carousel.new
assert carousel.invalid?
assert_has_errors_on carousel, [:label, :identifier]
end

def test_creation

assert_difference 'Carousel::Carousel.count' do
carousel = Carousel::Carousel.create(:identifier => 'test')
assert_equal 'Test', carousel.label
end
end

def test_destruction

assert_difference ['Carousel::Carousel.count', 'Carousel::Slide.count'], -1 do
carousel_carousels(:default).destroy
end
end

end

0 comments on commit a9597c3

Please sign in to comment.