<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>lib/core_ext/string.rb</filename>
    </added>
    <added>
      <filename>spec/unit/string_spec.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,11 +1,11 @@
 class Time
   def to_json(*a)
-    self.strftime(&quot;%Y/%m/%d %H:%M:%S %z&quot;)
+    strftime(&quot;%Y/%m/%d %H:%M:%S %z&quot;)
   end
-end
-
-class Time
-  def self.json_create(*o)
-    parse(*o)
+  
+  def self.parse string
+    return nil if string.nil?
+    d = DateTime.parse(string).new_offset
+    self.utc(d.year, d.month, d.day, d.hour, d.min, d.sec)
   end
 end</diff>
      <filename>lib/core_ext/time.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,3 @@
-require 'active_support'
 require 'couchrest'
 require 'json'
 require 'json/add/core'
@@ -15,6 +14,7 @@ end
 
 require File.dirname(__FILE__) + '/core_ext/object'
 require File.dirname(__FILE__) + '/core_ext/time'
+require File.dirname(__FILE__) + '/core_ext/string'
 require File.dirname(__FILE__) + '/couch_potato/persistence'
 require File.dirname(__FILE__) + '/couch_potato/active_record/compatibility'
 </diff>
      <filename>lib/couch_potato.rb</filename>
    </modified>
    <modified>
      <diff>@@ -11,7 +11,7 @@ module CouchPotato
   module Persistence
     
     class ValidationsFailedError &lt; ::Exception; end
-    class UnsavedRecordError &lt; ::Exception; end
+    class UnsavedDocumentError &lt; ::Exception; end
     
     def self.included(base)
       base.send :extend, ClassMethods
@@ -59,7 +59,7 @@ module CouchPotato
     end
 
     def reload
-      raise(UnsavedRecordError.new) unless _id
+      raise(UnsavedDocumentError.new) unless _id
       json = self.class.db.get _id
       self.class.properties.each do |property|
         property.build self, json
@@ -74,10 +74,6 @@ module CouchPotato
       _id
     end
     
-    # def [](name)
-    #       self.send name
-    #     end
-    
     def ==(other)
       other.class == self.class &amp;&amp; self.to_json == other.to_json
     end</diff>
      <filename>lib/couch_potato/persistence.rb</filename>
    </modified>
    <modified>
      <diff>@@ -50,7 +50,7 @@ module CouchPotato
       end
       
       def item_class_name
-        @name.to_s.singularize.camelcase
+        @name.to_s.camelize
       end
       
     end</diff>
      <filename>lib/couch_potato/persistence/belongs_to_property.rb</filename>
    </modified>
    <modified>
      <diff>@@ -11,20 +11,31 @@ module CouchPotato
         def view(name, options)
           map_function = options[:map] || map_function(options[:key], options[:properties])
           basic_view_options = options[:properties] || options[:map] ? {} : {:include_docs =&gt; true}
-          (class &lt;&lt; self; self; end).instance_eval do
+          self.class.instance_eval do
             define_method name do |view_options = {}|
               rows = ViewQuery.new(self.name.underscore, name, map_function).query_view!(basic_view_options.merge(view_options))
-              rows['rows'].map{|row| self.new(row['doc'] || row['value'].merge(:_id =&gt; row['id']))}
+              rows['rows'].map{|row|
+                self.json_create(row['doc'] || row['value'].merge(:_id =&gt; row['id']))
+              }
             end
           end
         end
         
         def map_function(key, properties)
           &quot;function(doc) {
-              emit(doc.#{key}, #{properties_for_map(properties)});
+              emit(#{formatted_key(key)}, #{properties_for_map(properties)});
            }&quot;
         end
         
+        def formatted_key(key)
+          if key.is_a? Array
+            '[' + key.map{|attribute| formatted_key(attribute)}.join(', ') + ']'
+          else
+            &quot;doc['#{key}']&quot;
+          end
+          
+        end
+        
         def properties_for_map(properties)
           if properties.nil?
             'null'</diff>
      <filename>lib/couch_potato/persistence/custom_view.rb</filename>
    </modified>
    <modified>
      <diff>@@ -37,8 +37,8 @@ module CouchPotato
           instance = self.new
           instance.created_at = Time.parse(json['created_at']) 
           instance.updated_at = Time.parse(json['updated_at'])
-          instance._id = json['_id']
-          instance._rev = json['_rev']
+          instance._id = json[:_id] || json['_id']
+          instance._rev = json[:_rev] || json['_rev']
           properties.each do |property|
             property.build(instance, json)
           end</diff>
      <filename>lib/couch_potato/persistence/json.rb</filename>
    </modified>
    <modified>
      <diff>@@ -38,7 +38,7 @@ module CouchPotato
       end
       
       def build(object, json)
-        object.send &quot;#{name}=&quot;, json.stringify_keys[name.to_s]
+        object.send &quot;#{name}=&quot;, json[name.to_s] || json[name.to_sym]
       end
       
       def dirty?(object)</diff>
      <filename>lib/couch_potato/persistence/simple_property.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,6 +2,6 @@
 
 require File.dirname(__FILE__) + '/../lib/couch_potato'
 
-CouchPotato::Config.database_name = YAML::load(File.read(RAILS_ROOT + '/config/couchdb.yml'))[RAILS_ENV]
+CouchPotato::Config.database_name = YAML::load(File.read(Rails.root.to_s + '/config/couchdb.yml'))[RAILS_ENV]
 
 RAILS_DEFAULT_LOGGER.info &quot;** couch_potato: initialized from #{__FILE__}&quot;</diff>
      <filename>rails/init.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,6 +8,7 @@ class Build
   
   view :timeline, :key =&gt; :time
   view :minimal_timeline, :key =&gt; :time, :properties =&gt; [:state]
+  view :key_array_timeline, :key =&gt; [:time, :state]
   view :custom_timeline, :map =&gt; &quot;function(doc) { emit(doc._id, {state: 'custom_' + doc.state}); }&quot;
   
 end
@@ -18,7 +19,7 @@ describe 'view' do
   end
   
   it &quot;should return instances of the class&quot; do
-    Build.db.save_doc({:state =&gt; 'success', :time =&gt; '2008-01-01'})
+    Build.create!(:state =&gt; 'success', :time =&gt; '2008-01-01')
     Build.timeline.map(&amp;:class).should == [Build]
   end
   
@@ -48,9 +49,11 @@ describe 'view' do
   
   describe &quot;no properties defined&quot; do
     it &quot;should assign all properties to the objects by default&quot; do
-      Build.db.save_doc({:state =&gt; 'success', :time =&gt; '2008-01-01'})
-      Build.timeline.first.state.should == 'success'
-      Build.timeline.first.time.should == '2008-01-01'
+      id = Build.db.save_doc({:state =&gt; 'success', :time =&gt; '2008-01-01'})['id']
+      result = Build.timeline.first
+      result.state.should == 'success'
+      result.time.should == '2008-01-01'
+      result._id.should == id
     end
   end
   
@@ -71,4 +74,11 @@ describe 'view' do
     end
   end
   
+  describe &quot;with array as key&quot; do
+    it &quot;should create a map function with the composite key&quot; do
+      CouchPotato::Persistence::ViewQuery.should_receive(:new).with(anything, anything, string_matching(/emit\(\[doc\['time'\], doc\['state'\]\]/)).and_return(stub('view query').as_null_object)
+      Build.key_array_timeline
+    end
+  end
+  
 end
\ No newline at end of file</diff>
      <filename>spec/custom_view_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -21,4 +21,10 @@ def recreate_db
   CouchPotato::Persistence.Db.delete! rescue nil
   CouchPotato::Persistence.Server.create_db CouchPotato::Config.database_name
 end
-recreate_db
\ No newline at end of file
+recreate_db
+
+Spec::Matchers.create :string_matching do |regex|
+  match do |string|
+    string =~ regex
+  end
+end</diff>
      <filename>spec/spec_helper.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>e0fedeb9dd61393be704755cffa3bdece1642b01</id>
    </parent>
  </parents>
  <author>
    <name>Alexander Lang</name>
    <email>alex@upstream-berlin.com</email>
  </author>
  <url>http://github.com/langalex/couch_potato/commit/0f5423210c4949b41fa10c1ecc118e2b1b078804</url>
  <id>0f5423210c4949b41fa10c1ecc118e2b1b078804</id>
  <committed-date>2009-03-28T16:25:26-07:00</committed-date>
  <authored-date>2009-03-28T16:25:26-07:00</authored-date>
  <message>removed activesupport dependency, custom views now support arrays as keys</message>
  <tree>318a0c857947230efdf83c4739b23d4552aae6ba</tree>
  <committer>
    <name>Alexander Lang</name>
    <email>alex@upstream-berlin.com</email>
  </committer>
</commit>
