0
-require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
0
-require __DIR__.parent.parent + 'lib/data_mapper'
0
-require __DIR__.parent.parent + 'lib/data_mapper/adapters/data_objects_adapter'
0
-require __DIR__.parent + 'adapter_shared_spec'
0
-describe DataMapper::Adapters::DataObjectsAdapter do
0
- @adapter = DataMapper::Adapters::DataObjectsAdapter.new(:default, URI.parse('mock://localhost'))
0
- it_should_behave_like 'a DataMapper Adapter'
0
- describe '#execute' do
0
- @mock_command = mock('Command', :execute_non_query => nil)
0
- @mock_db = mock('DB Connection', :create_command => @mock_command, :close => true)
0
- @adapter.stub!(:create_connection).and_return(@mock_db)
0
- it 'should #create_command from the sql passed' do
0
- @mock_db.should_receive(:create_command).with('SQL STRING').and_return(@mock_command)
0
- @adapter.execute('SQL STRING')
0
- it 'should pass any additional args to #execute_non_query' do
0
- @mock_command.should_receive(:execute_non_query).with(:args)
0
- @adapter.execute('SQL STRING', :args)
0
- it 'should return the result of #execute_non_query' do
0
- @mock_command.should_receive(:execute_non_query).and_return(:result_set)
0
- @adapter.execute('SQL STRING').should == :result_set
0
- it 'should log any errors, then re-raise them' do
0
- @mock_command.should_receive(:execute_non_query).and_raise("Oh Noes!")
0
- #DataMapper.logger.should_receive(:error)
0
- lambda { @adapter.execute('SQL STRING') }.should raise_error("Oh Noes!")
0
- it 'should always close the db connection' do
0
- @mock_command.should_receive(:execute_non_query).and_raise("Oh Noes!")
0
- @mock_db.should_receive(:close)
0
- lambda { @adapter.execute('SQL STRING') }.should raise_error("Oh Noes!")
0
- @mock_reader = mock('Reader', :fields => ['id', 'UserName', 'AGE'],
0
- :values => [1, 'rando', 27],
0
- @mock_command = mock('Command', :execute_reader => @mock_reader)
0
- @mock_db = mock('DB Connection', :create_command => @mock_command, :close => true)
0
- #make the while loop run exactly once
0
- @mock_reader.stub!(:next!).and_return(true, nil)
0
- @adapter.stub!(:create_connection).and_return(@mock_db)
0
- it 'should #create_command from the sql passed' do
0
- @mock_db.should_receive(:create_command).with('SQL STRING').and_return(@mock_command)
0
- @adapter.query('SQL STRING')
0
- it 'should pass any additional args to #execute_reader' do
0
- @mock_command.should_receive(:execute_reader).with(:args).and_return(@mock_reader)
0
- @adapter.query('SQL STRING', :args)
0
- describe 'returning multiple fields' do
0
- it 'should underscore the field names as members of the result struct' do
0
- @mock_reader.should_receive(:fields).and_return(['id', 'UserName', 'AGE'])
0
- result = @adapter.query('SQL STRING')
0
- result.first.members.should == %w{id user_name age}
0
- it 'should convert each row into the struct' do
0
- @mock_reader.should_receive(:values).and_return([1, 'rando', 27])
0
- @adapter.query('SQL STRING')
0
- it 'should add the row structs into the results array' do
0
- results = @adapter.query('SQL STRING')
0
- results.should be_kind_of(Array)
0
- row.should be_kind_of(Struct)
0
- row.user_name.should == 'rando'
0
- describe 'returning a single field' do
0
- it 'should add the value to the results array' do
0
- @mock_reader.should_receive(:fields).and_return(['username'])
0
- @mock_reader.should_receive(:values).and_return(['rando'])
0
- results = @adapter.query('SQL STRING')
0
- results.should be_kind_of(Array)
0
- results.first.should == 'rando'
0
- it 'should log any errors, then re-raise them' do
0
- @mock_command.should_receive(:execute_non_query).and_raise("Oh Noes!")
0
- #DataMapper.logger.should_receive(:error)
0
- lambda { @adapter.execute('SQL STRING') }.should raise_error("Oh Noes!")
0
- it 'should always close the db connection' do
0
- @mock_command.should_receive(:execute_non_query).and_raise("Oh Noes!")
0
- @mock_db.should_receive(:close)
0
- lambda { @adapter.execute('SQL STRING') }.should raise_error("Oh Noes!")
0
-describe DataMapper::Adapters::DataObjectsAdapter::SQL, "creating, reading, updating, deleting statements" do
0
- @adapter = DataMapper::Adapters::DataObjectsAdapter.new(:default, URI.parse('mock://localhost'))
0
- include DataMapper::Resource
0
- property :id, Fixnum, :serial => true
0
- property :name, String
0
- property :color, String
0
- property :notes, String, :lazy => true
0
- include DataMapper::Resource
0
- property :street, String, :key => true
0
- property :color, String, :key => true
0
- property :hillside, TrueClass, :default => true
0
- property :notes, String, :lazy => true
0
- describe "#create_statement" do
0
- it 'should generate a SQL statement for all fields' do
0
- @adapter.create_statement(Cheese, Cheese.properties(@adapter.name).slice(:name, :color)).should == <<-EOS.compress_lines
0
- INSERT INTO "cheeses" ("name", "color") VALUES (?, ?)
0
- it "should generate a SQL statement for only dirty fields" do
0
- @adapter.create_statement(Cheese, Cheese.properties(@adapter.name).slice(:name)).should == <<-EOS.compress_lines
0
- INSERT INTO "cheeses" ("name") VALUES (?)
0
- @adapter.create_statement(Cheese, Cheese.properties(@adapter.name).slice(:color)).should == <<-EOS.compress_lines
0
- INSERT INTO "cheeses" ("color") VALUES (?)
0
- describe "#create_statement_with_returning" do
0
- it 'should generate a SQL statement for all fields' do
0
- @adapter.create_statement_with_returning(Cheese, Cheese.properties(@adapter.name).slice(:name, :color)).should == <<-EOS.compress_lines
0
- INSERT INTO "cheeses" ("name", "color") VALUES (?, ?) RETURNING "id"
0
- it "should generate a SQL statement for only dirty fields" do
0
- @adapter.create_statement_with_returning(Cheese, Cheese.properties(@adapter.name).slice(:name)).should == <<-EOS.compress_lines
0
- INSERT INTO "cheeses" ("name") VALUES (?) RETURNING "id"
0
- @adapter.create_statement_with_returning(Cheese, Cheese.properties(@adapter.name).slice(:color)).should == <<-EOS.compress_lines
0
- INSERT INTO "cheeses" ("color") VALUES (?) RETURNING "id"
0
- describe "#update_statement" do
0
- it 'should generate a SQL statement for all fields' do
0
- @adapter.update_statement(Cheese, Cheese.properties(@adapter.name).slice(:name, :color)).should == <<-EOS.compress_lines
0
- it "should generate a SQL statement for only dirty fields" do
0
- @adapter.update_statement(Cheese, Cheese.properties(@adapter.name).slice(:name)).should == <<-EOS.compress_lines
0
- UPDATE "cheeses" SET "name" = ? WHERE "id" = ?
0
- @adapter.update_statement(Cheese, Cheese.properties(@adapter.name).slice(:color)).should == <<-EOS.compress_lines
0
- UPDATE "cheeses" SET "color" = ? WHERE "id" = ?
0
- it "should generate a SQL statement that includes a Composite Key" do
0
- @adapter.update_statement(LittleBox, LittleBox.properties(@adapter.name).slice(:hillside)).should == <<-EOS.compress_lines
0
- UPDATE "little_boxes" SET "hillside" = ? WHERE "street" = ? AND "color" = ?
0
- @adapter.update_statement(LittleBox, LittleBox.properties(@adapter.name).slice(:color, :hillside)).should == <<-EOS.compress_lines
0
- UPDATE "little_boxes" SET "color" = ?, "hillside" = ? WHERE "street" = ? AND "color" = ?
0
- describe "#delete_statement" do
0
- it 'should generate a SQL statement for a serial Key' do
0
- @adapter.delete_statement(Cheese).should == <<-EOS.compress_lines
0
- DELETE FROM "cheeses" WHERE "id" = ?
0
- it "should generate a SQL statement for a Composite Key" do
0
- @adapter.delete_statement(LittleBox).should == <<-EOS.compress_lines
0
- DELETE FROM "little_boxes" WHERE "street" = ? AND "color" = ?
0
- describe "#read_statement (without lazy attributes)" do
0
- it 'should generate a SQL statement for a serial Key' do
0
- @adapter.read_statement(Cheese, [1]).should == <<-EOS.compress_lines
0
- SELECT "id", "name", "color" FROM "cheeses" WHERE "id" = ?
0
- it "should generate a SQL statement that includes a Composite Key" do
0
- @adapter.read_statement(LittleBox, ['Shady Drive', 'Blue']).should == <<-EOS.compress_lines
0
- SELECT "street", "color", "hillside" FROM "little_boxes" WHERE "street" = ? AND "color" = ?
0
- describe '#uri options' do
0
- it 'should transform a fully specified option hash into a URI' do
0
- :host => 'davidleal.com',
0
- :password => 'mypass',
0
- :database => 'you_can_call_me_al',
0
- adapter = DataMapper::Adapters::DataObjectsAdapter.allocate
0
- adapter.uri(options).should ==
0
- URI.parse("mysql://me:mypass@davidleal.com:5000/you_can_call_me_al?socket=nosock")
0
- it 'should transform a minimal options hash into a URI' do
0
- :database => 'you_can_call_me_al'
0
- adapter = DataMapper::Adapters::DataObjectsAdapter.allocate
0
- adapter.uri(options).should == URI.parse("mysql:///you_can_call_me_al")
0
- it 'should accept the uri when no overrides exist' do
0
- uri = URI.parse("protocol:///")
0
- DataMapper::Adapters::DataObjectsAdapter.allocate.uri(uri).should == uri