Created
January 19, 2011 12:05
-
-
Save gorkunov/786073 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
require 'rake' | |
DOMAIN = CONNECTION_PARAMS[:domain_name] | |
def delete_domain_if_exist | |
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS) | |
con = ActiveRecord::Base.connection | |
con.delete_domain(DOMAIN) if con.list_domains.include? DOMAIN | |
end | |
def recreate_domain | |
delete_domain_if_exist | |
ActiveRecord::Base.connection.create_domain DOMAIN | |
end | |
#create mock Rails | |
class ::Rails | |
def self.logger | |
@@logger ||= Logger.new(STDOUT) | |
end | |
def self.env | |
"development" | |
end | |
def self.root | |
File.dirname(__FILE__) + "/../assets" | |
end | |
end | |
describe "gem rake tasks" do | |
before do | |
@rake = Rake::Application.new | |
Rake.application = @rake | |
Rake.application.rake_require "tasks/simpledb" | |
Rake::Task.define_task(:environment) | |
ActiveRecord::Base.stub!(:configurations).and_return({"development" => CONNECTION_PARAMS}) | |
end | |
def self.for_task task_name, &block | |
describe "rake #{task_name}" do | |
it "should have 'environment' as a prereq" do | |
@rake[task_name].prerequisites.should include("environment") | |
end | |
block.call task_name | |
end | |
end | |
for_task "db:create" do |task_name| | |
before do | |
puts "1" | |
delete_domain_if_exist | |
end | |
it "should create sdb domain" do | |
@rake[task_name].invoke | |
ActiveRecord::Base.connection.list_domains.should include(DOMAIN) | |
end | |
end | |
for_task "db:seed" do |task_name| | |
before do | |
puts "2" | |
recreate_domain | |
end | |
it "should pushing data to sdb domain" do | |
@rake[task_name].invoke | |
puts Person.all.inspect | |
Person.count.should == 1 | |
end | |
end | |
for_task "db:collection:clear" do |task_name| | |
before do | |
puts "3" | |
recreate_domain | |
Person.create!(Person.valid_params) | |
end | |
it "should clear collection by name" do | |
@rake[task_name].invoke("people") | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment