Permalink
Browse files

Working on framework fixtures

  • Loading branch information...
1 parent b019166 commit 3bb4a934387577093086245d1ab61db3c90ef39d @winton committed Dec 29, 2010
View
@@ -2,8 +2,8 @@
*.gem
coverage
pkg
-spec/config/database.yml
-spec/fixtures/build
-spec/log
+spec/fixtures/config/database.yml
+spec/fixtures/builds
+spec/fixtures/log
tmp
vendor
@@ -4,56 +4,21 @@
describe ActsAsArchive do
before(:each) do
- [ 8, 0, 8 ].each { |v| $db.migrate(v) }
- @record, @lengths, @zero_lengths = setup_records
+ before_each
end
it "should create records" do
- original, archive = all_records
- verify_lengths original, @lengths
- verify_attributes original
+ should_create_records
end
%w(delete delete_all destroy destroy_all).each do |type|
describe type do
it "should move records to archive tables" do
- case type
- when 'delete', 'destroy'
- @record.send type
- when 'delete_all', 'destroy_all'
- Record.send type
- end
-
- original, archive = all_records
-
- case type
- when 'delete', 'delete_all'
- archive[:record].length.should == 1
- original[:record].length.should == 0
-
- verify_lengths archive, @zero_lengths, :exclude => [ :record ]
- verify_lengths original, @lengths, :exclude => [ :record ]
-
- verify_attributes archive, :only => [ :record ]
-
- when 'destroy', 'destroy_all'
- verify_lengths archive, @lengths
- verify_lengths original, @zero_lengths
-
- verify_attributes archive
- end
+ should_move_records_to_archive_tables(type)
end
it "should move records back to original tables" do
- @record.destroy
- Record::Archive.first.destroy
-
- original, archive = all_records
-
- verify_lengths original, @lengths
- verify_lengths archive, @zero_lengths
-
- verify_attributes original
+ should_move_records_back_to_original_tables
end
end
end
@@ -68,10 +33,33 @@
def app
FrameworkFixture.app.call
end
+
+ before(:each) do
+ `#{$root}/spec/fixtures/before_each`
+ end
it "should have a pulse" do
get "/pulse"
last_response.body.should == '1'
end
+
+ it "should create records" do
+ get "/should_create_records_action"
+ last_response.body.should == '1'
+ end
+
+ %w(delete delete_all destroy destroy_all).each do |type|
+ describe type do
+ it "should move records to archive tables" do
+ get "/should_move_records_to_archive_tables_action", :type => type
+ last_response.body.should == '1'
+ end
+
+ it "should move records back to original tables" do
+ get "/should_move_records_back_to_original_tables_action"
+ last_response.body.should == '1'
+ end
+ end
+ end
end
end
@@ -0,0 +1,20 @@
+#!/usr/bin/env ruby
+
+$root = File.expand_path('../../../', __FILE__)
+require "#{$root}/lib/acts_as_archive/gems"
+
+ActsAsArchive::Gems.require(:spec_non_framework)
+
+require 'active_support/dependencies'
+require 'active_wrapper'
+
+$db, $log, $mail = ActiveWrapper.setup(
+ :base => "#{$root}/spec/fixtures",
+ :env => 'test'
+)
+$db.establish_connection
+
+ActiveSupport::Dependencies.autoload_paths << "#{$root}/spec/fixtures/helpers"
+include SpecHelper
+
+before_each true, false
@@ -1,12 +1,14 @@
rails:
<3:
+ config:
+ - config/database.yml
frameworks/rails2:
- app/controllers/application_controller.rb
- config/routes.rb
- vendor/plugins/plugin/rails/init.rb
- helpers: &helpers
- - app/helpers/verify_helper.rb
- models: &models
+ helpers:
+ - app/helpers/spec_helper.rb
+ models:
- app/models/belongs_to.rb
- app/models/has_many.rb
- app/models/has_many_through.rb
@@ -15,19 +17,21 @@ rails:
- app/models/has_one_through.rb
- app/models/has_one_through_through.rb
- app/models/record.rb
- <4:
- frameworks/rails3:
- - app/controllers/application_controller.rb
- - config/routes.rb
- - Gemfile
- helpers:
- <<: *helpers
- models:
- <<: *models
-sinatra:
- <1:
- frameworks/sinatra:
- - application.rb
- <2:
- frameworks/sinatra:
- - application.rb
+# <4:
+# config:
+# <<: *config
+# frameworks/rails3:
+# - app/controllers/application_controller.rb
+# - config/routes.rb
+# - Gemfile
+# helpers:
+# <<: *helpers
+# models:
+# <<: *models
+# sinatra:
+# <1:
+# frameworks/sinatra:
+# - application.rb
+# <2:
+# frameworks/sinatra:
+# - application.rb
@@ -8,7 +8,27 @@ class ApplicationController < ActionController::Base
# Scrub sensitive parameters from your log
# filter_parameter_logging :password
+ include SpecHelper
+
def pulse
render :text => '1'
end
+
+ def should_create_records_action
+ before_each false, true
+ should_create_records
+ render :text => '1'
+ end
+
+ def should_move_records_back_to_original_tables_action
+ before_each false, true
+ should_move_records_back_to_original_tables
+ render :text => '1'
+ end
+
+ def should_move_records_to_archive_tables_action
+ before_each false, true
+ should_move_records_to_archive_tables(params[:type])
+ render :text => '1'
+ end
end
@@ -42,5 +42,5 @@
# map.connect ':controller/:action/:id'
# map.connect ':controller/:action/:id.:format'
- map.connect 'pulse', :controller => 'application', :action => 'pulse'
+ map.connect ':action', :controller => 'application'
end
@@ -1,4 +1,4 @@
-module VerifyHelper
+module SpecHelper
def all_records
[
@@ -25,6 +25,15 @@ def all_records
]
end
+ def before_each(migrate=true, setup=true)
+ if migrate
+ [ 8, 0, 8 ].each { |v| $db.migrate(v) }
+ end
+ if setup
+ @record, @lengths, @zero_lengths = setup_records
+ end
+ end
+
def setup_records
record = Record.create :belongs_to_id => BelongsTo.create.id
@@ -56,6 +65,52 @@ def setup_records
[ record, lengths, zero_lengths ]
end
+
+ def should_create_records
+ original, archive = all_records
+ verify_lengths original, @lengths
+ verify_attributes original
+ end
+
+ def should_move_records_back_to_original_tables
+ @record.destroy
+ Record::Archive.first.destroy
+
+ original, archive = all_records
+
+ verify_lengths original, @lengths
+ verify_lengths archive, @zero_lengths
+
+ verify_attributes original
+ end
+
+ def should_move_records_to_archive_tables(type)
+ case type
+ when 'delete', 'destroy'
+ @record.send type
+ when 'delete_all', 'destroy_all'
+ Record.send type
+ end
+
+ original, archive = all_records
+
+ case type
+ when 'delete', 'delete_all'
+ archive[:record].length.should == 1
+ original[:record].length.should == 0
+
+ verify_lengths archive, @zero_lengths, :exclude => [ :record ]
+ verify_lengths original, @lengths, :exclude => [ :record ]
+
+ verify_attributes archive, :only => [ :record ]
+
+ when 'destroy', 'destroy_all'
+ verify_lengths archive, @lengths
+ verify_lengths original, @zero_lengths
+
+ verify_attributes archive
+ end
+ end
def verify_attributes(records, options={})
options[:exclude] ||= []
View
@@ -19,16 +19,17 @@
require "#{$root}/lib/acts_as_archive"
ActiveSupport::Dependencies.autoload_paths << "#{$root}/spec/fixtures/models"
- ActiveSupport::Dependencies.autoload_paths << "#{$root}/spec/fixtures/helpers"
$db, $log, $mail = ActiveWrapper.setup(
- :base => File.dirname(__FILE__),
+ :base => "#{$root}/spec/fixtures",
:env => 'test'
)
$db.establish_connection
-
- include VerifyHelper
end
+ActiveSupport::Dependencies.autoload_paths << "#{$root}/spec/fixtures/helpers"
+
+include SpecHelper
+
Spec::Runner.configure do |config|
end

0 comments on commit 3bb4a93

Please sign in to comment.