Skip to content

Commit

Permalink
Merge branch 'james' into integration
Browse files Browse the repository at this point in the history
Conflicts:
	lib/active_presenter/base.rb
	lib/active_presenter/version.rb
  • Loading branch information
francois committed Jan 26, 2009
2 parents d31fc60 + 0b82d06 commit 66158e1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/active_presenter/base.rb
Expand Up @@ -57,12 +57,16 @@ def initialize(args = {})

self.attributes = args
end
<<<<<<< HEAD:lib/active_presenter/base.rb

def id
return nil if presented_instances.map(&:new_record?).all?
presented_instances.detect {|i| !i.new_record?}.id
end

=======

>>>>>>> james:lib/active_presenter/base.rb
# Set the attributes of the presentable instances using the type_attribute form (i.e. user_login => 'james')
#
def attributes=(attrs)
Expand Down Expand Up @@ -148,6 +152,7 @@ def update_attributes(attrs)
save
end

<<<<<<< HEAD:lib/active_presenter/base.rb
# Should this presented instance be saved? By default, this returns true
# Called from #save and #save!
#
Expand All @@ -163,6 +168,17 @@ def save?(presented_key, presented_instance)
true
end

=======
# We define #id and #new_record? to play nice with form_for(@presenter) in Rails
def id # :nodoc:
nil
end

def new_record?
true
end

>>>>>>> james:lib/active_presenter/base.rb
protected
def presented_instances
presented.keys.map { |key| send(key) }
Expand Down
8 changes: 8 additions & 0 deletions test/base_test.rb
@@ -1,6 +1,14 @@
require File.dirname(__FILE__)+'/test_helper'

Expectations do
expect nil do
SignupPresenter.new.id
end

expect true do
SignupPresenter.new.new_record?
end

expect :user => User, :account => Account do
SignupPresenter.presented
end
Expand Down

0 comments on commit 66158e1

Please sign in to comment.