require File.join(File.dirname(__FILE__), '..', 'lib/hydroponics') require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "Hydroponics::Setup" do include Hydroponics::Setup describe "#get_db_from_local_rails_project" do it "should raise an error if it can't find a rails-style database yml" do lambda { get_db_from_local_rails_project() }.should raise_error lambda { get_db_from_local_rails_project("nope") }.should raise_error end it "should set db to a Sequel::Database object" do get_db_from_local_rails_project(File.dirname(__FILE__)) Hydroponics.db.should be_a(Sequel::Database) end it "should output the config" do get_db_from_local_rails_project(File.dirname(__FILE__)).should be_a(Hash) end end describe "#convert_rails_yml_to_sequel_config" do it "should fail if not given a properly formatted hash" do lambda { convert_rails_yml_to_sequel_config }.should raise_error lambda { convert_rails_yml_to_sequel_config("string") }.should raise_error lambda { convert_rails_yml_to_sequel_config({"username" => "blah"}) }.should raise_error end it "should convert 'username' to 'user'" do hash = {"development" => {"username" => "blah", "user" => "blah2"}} convert_rails_yml_to_sequel_config(hash)[:user].should == "blah" end it "should use the development environment" do hash = {"development" => {"username" => "dev"}, "test" => {"username" => "blah"}} convert_rails_yml_to_sequel_config(hash)[:user].should == "dev" end end describe "#raise_max_packet_size" do it "should run the right query" do db = mock("db") db.should_receive(:execute).with("set global max_allowed_packet=1048576000;") Hydroponics.stub!(:db).and_return(db) raise_max_packet_size end end end describe "Hydroponics::Actions" do include Hydroponics::Actions before(:all) do @db = prepare_test_db end before(:each) do populate_test_db end describe "#dupe" do it "should duplicate the first user until the desired count is reached" do dupe(:users, 10) @db[:users].count.should == 10 end it "should delete users from the end until the desired count is reached" do @db[:users].multi_insert([{:name => "ABC", :email => "123@example.com"}] * 10) @db[:users].count.should == 11 dupe(:users, 2) @db[:users].count.should == 2 end it "should require the table name and count" do lambda { dupe }.should raise_error lambda { dupe(:users) }.should raise_error lambda { dupe(16) }.should raise_error end end end