Created
July 7, 2010 05:16
-
-
Save hakanai/466334 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Licence < ActiveRecord::Base | |
belongs_to :parent_licence, :class_name => 'Licence' | |
has_many :nested_licences, :class_name => 'Licence', :foreign_key => 'parent_licence_id', :dependent => :destroy | |
accepts_nested_attributes_for :nested_licences | |
validates_associated :nested_licences | |
def clone | |
cloned = super | |
cloned.nested_licences = nested_licences.map { |nested_licence| nested_licence.clone } | |
cloned | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# So I have this fixture, but when running any tests which use it, Licence.find(1).nested_licences is always empty. | |
licence_1: | |
id: 1 | |
organisation_id: 1 | |
user_id: 1 | |
owner_organisation_id: 2 | |
owner: 'TwoCorp' | |
dongle_id: 2 | |
profile_id: 5 # server | |
expiry: '2009-11-01' | |
success: true | |
notes: 'Server licence' | |
created_at: '2009-01-01 00:00:00' | |
licence_1_1: | |
id: 4 | |
organisation_id: 1 | |
user_id: 1 | |
parent_licence_id: 1 | |
count: 3 | |
profile_id: 1 # legal desktop | |
expiry: '2009-11-01' | |
load_worker_count: 8 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment