From b65033d2c8054a2b9979614550b562ea9485b2cf Mon Sep 17 00:00:00 2001 From: winton Date: Sat, 25 Apr 2009 21:45:28 -0700 Subject: [PATCH] Spec for base.rb...rcov looks good, calling it a day on specs --- .gitignore | 1 + Rakefile | 1 + spec/acts_as_archive/base_spec.rb | 24 ++++++++++++++++++++++++ spec/spec_helper.rb | 9 ++++----- 4 files changed, 30 insertions(+), 5 deletions(-) create mode 100644 spec/acts_as_archive/base_spec.rb diff --git a/.gitignore b/.gitignore index ceb34df..9c73ebd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store *.gem +coverage tmp spec/db/log/*.log \ No newline at end of file diff --git a/Rakefile b/Rakefile index 8c06d0d..d80be8a 100644 --- a/Rakefile +++ b/Rakefile @@ -42,6 +42,7 @@ end desc "Run specs" Spec::Rake::SpecTask.new do |t| + t.rcov = true t.spec_opts = ["--format", "specdoc", "--colour"] t.spec_files = FileList["spec/**/*_spec.rb"] end \ No newline at end of file diff --git a/spec/acts_as_archive/base_spec.rb b/spec/acts_as_archive/base_spec.rb new file mode 100644 index 0000000..330ca04 --- /dev/null +++ b/spec/acts_as_archive/base_spec.rb @@ -0,0 +1,24 @@ +require File.expand_path(File.dirname(__FILE__) + "/../spec_helper") + +describe ActsAsArchive::Base do + + before(:all) do + establish_test_db + end + + describe 'acts_as_archive' do + + it "should add self.acts_as_archive? to the model" do + Article.respond_to?(:acts_as_archive?).should == true + end + + it "should add self.archive_indexes to the model" do + Article.respond_to?(:archive_indexes).should == true + Article.archive_indexes.should == [ 'id', 'deleted_at' ] + end + + it "should add Archive class to the model" do + defined?(Article::Archive).should == "constant" + end + end +end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ddaddc4..8b1a05b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,5 @@ $TESTING=true -SPEC = File.dirname(__FILE__) +SPEC = File.expand_path(File.dirname(__FILE__)) require 'rubygems' require 'active_record' @@ -72,17 +72,16 @@ def establish_test_db logger_file.sync = true @logger = Logger.new(logger_file) ActiveRecord::Base.logger = @logger - # Drop articles and archived_articles + # The database should have only a simple articles table connection.execute("DROP TABLE IF EXISTS articles") connection.execute("DROP TABLE IF EXISTS archived_articles") connection.execute("DROP TABLE IF EXISTS schema_migrations") - # Create articles table connection.create_table(:articles) do |t| t.string :title t.string :body end - # Load model - require "#{SPEC}/db/models/article" + # Load the model + load "#{SPEC}/db/models/article.rb" end def indexes