Commit 89007b3

mo khan <mo@mokhan.ca>
2014-06-13 03:10:36
remove extra attributes hashes and comments.
1 parent 7a3079c
lib/humble/column.rb
@@ -8,7 +8,6 @@ module Humble
 
     def prepare(entity)
       return {} if primary_key? && has_default_value?(entity)
-      #{ column_name.to_sym => entity.instance_variable_get("@#{column_name}") }
       { column_name.to_sym => entity.public_send(column_name.to_sym) }
     end
 
lib/humble/database_table.rb
@@ -43,7 +43,6 @@ module Humble
     def map_from(row)
       entity = type.new
       row.each do |key, value|
-        #entity.send("#{key}=", value) unless key == :studio_id
         column_for(key).apply(value, entity)
       end
       entity
lib/humble/mapping_configuration.rb
@@ -1,7 +1,6 @@
 module Humble
   class MappingConfiguration
-    def initialize(attributes, table)
-      @attributes = attributes
+    def initialize(table)
       @table = table
     end
 
@@ -18,11 +17,11 @@ module Humble
     end
 
     def matches?(item)
-      self[:type] == item || item.is_a?(self[:type])
+      type == item || item.is_a?(type)
     end
 
-    def [](key)
-      @attributes[key]
+    def type
+      @table.type
     end
   end
 end
lib/humble/mapping_configuration_builder.rb
@@ -1,22 +1,18 @@
 module Humble
   class MappingConfigurationBuilder
-    def initialize(attributes = {}, table = DatabaseTable.new)
-      @attributes = attributes
+    def initialize(table = DatabaseTable.new)
       @table = table
     end
 
     def table(name)
-      @attributes[:table] = name
       @table.named(name)
     end
 
     def type(name)
-      @attributes[:type] = name
       @table.type=name
     end
 
     def primary_key(name, default: 0)
-      @attributes[:primary_key] = name
       @table.primary_key(name, default: default)
     end
 
@@ -29,7 +25,7 @@ module Humble
     end
 
     def build
-      MappingConfiguration.new(@attributes, @table)
+      MappingConfiguration.new(@table)
     end
   end
 end
spec/integration/select_spec.rb
@@ -29,15 +29,25 @@ describe "select items" do
   end
 
   context "when fetching a single item" do
-    it "loads the belongs_to association" do
-      studio_id = connection[:studios].insert(name: 'universal')
-      movie_id = connection[:movies].insert(name: 'blood in, blood out', studio_id: studio_id)
+    let!(:studio_id) { connection[:studios].insert(name: 'universal') }
+    let!(:movie_id) { connection[:movies].insert(name: 'blood in, blood out', studio_id: studio_id) }
+    let(:result) { session.find(Movie, movie_id) }
 
-      result = session.find(Movie, movie_id)
+    it "loads the proper type" do
       expect(result).to be_instance_of(Movie)
+    end
+
+    it "loads the primary key" do
       expect(result.id).to eql(movie_id)
+    end
+
+    it "loads each mapped column" do
       expect(result.name).to eql('blood in, blood out')
+    end
+
+    it "loads the belongs_to association" do
       expect(result.studio).to be_instance_of(Studio)
+      expect(result.studio.name).to eql('universal')
     end
   end
 end