summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2013-07-19 22:44:46 -0600
committermo khan <mo@mokhan.ca>2013-07-19 22:44:46 -0600
commit1c98d45a3726cf29ffdc10bd69ae087432ba7aba (patch)
treedb3afe0da3fd3ef158dd6d65ac35f63c1d5425ce
parent071d480293050d76f5d53b6a6d646f2323b91594 (diff)
install humble and start to build product mapping
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock3
-rw-r--r--lib/orm/database_configuration.rb6
-rw-r--r--lib/orm/mappings/product_mapping.rb10
-rw-r--r--spec/integration/orm/mappings/product_mapping_spec.rb20
-rw-r--r--spec/spec_helper.rb1
6 files changed, 40 insertions, 1 deletions
diff --git a/Gemfile b/Gemfile
index a740d17..c8a7e12 100644
--- a/Gemfile
+++ b/Gemfile
@@ -7,6 +7,7 @@ gem 'pg'
gem 'oauth2'
gem 'bcrypt-ruby'
gem 'spank'
+gem 'humble'
group :development do
gem 'mongrel', '>= 1.1.5.pre'
diff --git a/Gemfile.lock b/Gemfile.lock
index d5c59ce..6904f5a 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -18,6 +18,8 @@ GEM
gem_plugin (0.2.3)
headless (1.0.1)
httpauth (0.2.0)
+ humble (0.0.1369313534)
+ sequel
jwt (0.1.8)
multi_json (>= 1.5)
kgio (2.8.0)
@@ -73,6 +75,7 @@ DEPENDENCIES
bcrypt-ruby
fakes-rspec
headless
+ humble
mongrel (>= 1.1.5.pre)
oauth2
pg
diff --git a/lib/orm/database_configuration.rb b/lib/orm/database_configuration.rb
index cda49b0..702514c 100644
--- a/lib/orm/database_configuration.rb
+++ b/lib/orm/database_configuration.rb
@@ -3,7 +3,11 @@ require 'pg'
class DatabaseConfiguration
def configure(connection)
- connection.connect(ENV['DATABASE_URL'] || build_connection_string)
+ connection.connect(connection_string)
+ end
+
+ def connection_string
+ ENV['DATABASE_URL'] || build_connection_string
end
private
diff --git a/lib/orm/mappings/product_mapping.rb b/lib/orm/mappings/product_mapping.rb
new file mode 100644
index 0000000..6dc0688
--- /dev/null
+++ b/lib/orm/mappings/product_mapping.rb
@@ -0,0 +1,10 @@
+require 'product'
+
+class ProductMapping < Humble::DatabaseMapping
+ def run(map)
+ map.table :products
+ map.type Product
+ map.primary_key(:id, :default => -1)
+ map.column :name
+ end
+end
diff --git a/spec/integration/orm/mappings/product_mapping_spec.rb b/spec/integration/orm/mappings/product_mapping_spec.rb
new file mode 100644
index 0000000..4480638
--- /dev/null
+++ b/spec/integration/orm/mappings/product_mapping_spec.rb
@@ -0,0 +1,20 @@
+require "spec_helper"
+
+describe "Product Mapping" do
+ context "finding all products" do
+ let(:product) { Product.new(:name => 'book') }
+ before :each do
+ connection_string = DatabaseConfiguration.new.connection_string
+ configuration = Humble::Configuration.new(connection_string)
+ configuration.add(ProductMapping.new)
+ session_factory = configuration.build_session_factory
+ @session = session_factory.create_session
+ end
+
+ let(:results) { @session.find_all(Product) }
+
+ it "should be able to load all Products" do
+ results.should include(product)
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 3cc9f2a..9a3b168 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -3,6 +3,7 @@ if ENV['CI']
SimpleCov.start
end
require 'fakes-rspec'
+require 'humble'
require_relative 'integration/orm/test_database_gateway'
Dir.glob("lib/**/*.rb").each { |x| $:.unshift(File.dirname(x)) }
Dir.glob("lib/**/*.rb").each { |x| require File.basename(x) }