Skip to content

Commit

Permalink
test, better ci
Browse files Browse the repository at this point in the history
  • Loading branch information
GBH committed Jan 25, 2015
1 parent 5010044 commit 87b91cd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ before_install:
before_script:
- rake db:migrate
script:
- rake test:all
- rake ci
rvm:
- 1.9.3
- 2.0.0
Expand Down
18 changes: 14 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
require_relative 'config/application'
require 'bundler'
Bundler.setup

require 'rake/testtask'

Rake::TestTask.new(:ci) do |t|
t.libs << 'test'
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end

require_relative 'config/application'
ComfyBlog::Application.load_tasks

namespace :test do

Rake::TestTask.new(:lib) do |t|
t.libs << 'test'
t.pattern = 'test/lib/**/*_test.rb'
t.verbose = true
end

Rake::TestTask.new(:generators) do |t|
t.libs << 'test'
t.pattern = 'test/generators/**/*_test.rb'
t.verbose = true
end

end

Rake::Task[:test].enhance do
Expand Down
2 changes: 2 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@

# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

config.active_support.test_order = :random
end
27 changes: 18 additions & 9 deletions test/models/posts_test.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
require_relative '../test_helper'

class BlogPostsTest < ActiveSupport::TestCase

def test_fixtures_validity
Comfy::Blog::Post.all.each do |post|
assert post.valid?, post.errors.full_messages.to_s
end
end

def test_validations
post = Comfy::Blog::Post.new
assert post.invalid?
assert_errors_on post, :blog_id, :title, :slug, :content
end

def test_validation_of_slug_uniqueness
old_post = comfy_blog_posts(:default)
old_post.update_attributes!(:published_at => Time.now)
Expand All @@ -27,7 +27,16 @@ def test_validation_of_slug_uniqueness
old_post.update_attributes!(:published_at => 1.year.ago)
assert post.valid?
end


def test_validation_of_slug_format
post = comfy_blog_blogs(:default).posts.new(
:title => 'Test Title',
:slug => 'test%slug',
:content => 'Test Content'
)
assert post.valid?
end

def test_creation
assert_difference 'Comfy::Blog::Post.count' do
post = comfy_blog_blogs(:default).posts.create!(
Expand All @@ -39,27 +48,27 @@ def test_creation
assert_equal Time.now.month, post.month
end
end

def test_set_slug
post = Comfy::Blog::Post.new(:title => 'Test Title')
post.send(:set_slug)
assert_equal 'test-title', post.slug
end

def test_set_date
post = Comfy::Blog::Post.new
post.send(:set_published_at)
post.send(:set_date)
assert_equal post.published_at.year, post.year
assert_equal post.published_at.month, post.month
end

def test_set_published_at
post = Comfy::Blog::Post.new
post.send(:set_published_at)
assert post.published_at.present?
end

def test_destroy
assert_difference ['Comfy::Blog::Post.count', 'Comfy::Blog::Comment.count'], -1 do
comfy_blog_posts(:default).destroy
Expand All @@ -84,5 +93,5 @@ def test_scope_for_month
assert_equal 1, Comfy::Blog::Post.for_month(1).count
assert_equal 0, Comfy::Blog::Post.for_month(2).count
end

end

0 comments on commit 87b91cd

Please sign in to comment.