Permalink
Browse files

- added associations module

- added asociations unit test file
  • Loading branch information...
1 parent d40ca9c commit 7d3da5bb769b0e94907306e9896670bca13893c7 @gramos committed Sep 27, 2010
@@ -0,0 +1,8 @@
+module ActiveResource
+ module Associations
+
+ def has_one(resource, opts = {})
+ end
+
+ end
+end
@@ -18,6 +18,7 @@
require 'active_resource/formats'
require 'active_resource/schema'
require 'active_resource/log_subscriber'
+require 'active_resource/associations'
module ActiveResource
# ActiveResource::Base is the main class for mapping RESTful resources as models in a Rails application.
@@ -262,7 +263,7 @@ class Base
# :singleton-method:
# The logger for diagnosing and tracing Active Resource calls.
cattr_accessor :logger
-
+ extend Associations
class << self
# Creates a schema for this resource - setting the attributes that are
# known prior to fetching an instance from the remote system.
@@ -0,0 +1,14 @@
+require 'abstract_unit'
+require "fixtures/project"
+
+class AssociationsTest < Test::Unit::TestCase
+
+ def setup
+ @project = Project.new
+ end
+
+ def test_has_one_should_add_a_resource_accessor
+ assert @project.respond_to? :project_manager
+ end
+end
+
@@ -2,6 +2,14 @@
class Project < ActiveResource::Base
self.site = "http://37s.sunrise.i:3000"
+ #----------------------------------------------------------------------
+ # associations
+ #
+ has_one :project_manager
+
+ #----------------------------------------------------------------------
+ # validations
+ #
validates_presence_of :name
validate :description_greater_than_three_letters
@@ -18,6 +26,7 @@ def description_greater_than_three_letters
def name
attributes['name'] || nil
end
+
def description
attributes['description'] || nil
end

0 comments on commit 7d3da5b

Please sign in to comment.