Skip to content

Commit

Permalink
add Extension spec
Browse files Browse the repository at this point in the history
  • Loading branch information
relax4u committed Aug 8, 2011
1 parent e2d555d commit acc4c75
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
5 changes: 3 additions & 2 deletions millstone.gemspec
Expand Up @@ -3,13 +3,13 @@ $:.push File.expand_path("../lib", __FILE__)

Gem::Specification.new do |s|
s.name = 'millstone'
s.version = '0.1.0'
s.version = '0.0.1'
s.platform = Gem::Platform::RUBY
s.authors = ['Yoshikazu Ozawa']
s.email = ['yoshikazu.ozawa@gmail.com']
s.homepage = 'https://github.com/relax4u/millstone'
s.summary = 'ActiveRecord plugin which allows you to hide without actually deleting them for Rails3.'
s.description = 'Millstone is ActiveRecord plugin which allows you to hide without actually deleting them for Rails3.'
s.description = 'ActiveRecord plugin which allows you to hide without actually deleting them for Rails3. Millstone is extending ActiveRecord::Relation'

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
Expand All @@ -23,4 +23,5 @@ Gem::Specification.new do |s|
s.add_development_dependency 'sqlite3', ['>= 0']
s.add_development_dependency 'rspec', ['>= 2.0.0']
s.add_development_dependency 'rspec-rails', ['>= 2.0.0']
s.add_development_dependency 'delorean', ['>= 0']
end
55 changes: 55 additions & 0 deletions spec/models/extension_spec.rb
@@ -0,0 +1,55 @@
require 'spec_helper'

class MillstoneTimeModel < ActiveRecord::Base
set_table_name 'time_columns'
millstone
end

class MillstoneBooleanModel < ActiveRecord::Base
set_table_name 'boolean_columns'
millstone :column => :deleted, :type => :boolean
end

describe Millstone::ActiveRecord::Extension do
describe ActiveRecord::Base do
let(:record) { klass.create!(:context => "name") }
let(:deleted_record) { klass.with_deleted.first }

shared_examples "execute destroy and destroy!" do
describe "#destroy" do
before { record.destroy }

specify { deleted_record.should eq record }
specify { deleted_record.should be_deleted }
end

describe "#destroy!" do
before { record.destroy! }
specify { deleted_record.should be_nil }
end
end

context "as millstone :type => :boolean" do
let(:klass) { MillstoneBooleanModel }

it_behaves_like "execute destroy and destroy!"

describe "#destroy" do
before { record.destroy }
specify { deleted_record.deleted.should be_true }
end
end

context "as millstone :type => :time" do
before { Delorean.time_travel_to 1.hour.ago }
after { Delorean.back_to_the_present }

let(:klass) { MillstoneTimeModel }

describe "#destroy" do
before { record.destroy }
specify { deleted_record.deleted_at.to_s.should == Time.now.to_s }
end
end
end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -5,6 +5,7 @@
require 'active_record'
require 'action_controller'
require 'action_view'
require 'delorean'
require 'millstone'

require 'rspec/rails'
Expand All @@ -14,6 +15,7 @@
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}

RSpec.configure do |config|
config.include Delorean
config.mock_with :rspec
config.fixture_path = File.join(File.dirname(__FILE__), 'fixtures')
config.use_transactional_fixtures = true
Expand Down

0 comments on commit acc4c75

Please sign in to comment.