Skip to content
Browse files

original proxy tests (passing)

  • Loading branch information...
1 parent 3d7cda2 commit a775c800bc4463def88923e76b35d4e1146bdb73 @madskaddie madskaddie committed
Showing with 57 additions and 52 deletions.
  1. +16 −52 scheduler/lib/radia_source/lightweight/original.rb
  2. +41 −0 scheduler/test/unit/lightweight/original_test.rb
View
68 scheduler/lib/radia_source/lightweight/original.rb
@@ -3,66 +3,30 @@ module LightWeight
class Original < Broadcast
- attr_accessor :program
- def initialize(args=nil)
- super(args)
- unless args.nil?
- @program = args[:program]
- @structure_template = args[:structure_template]
- end
- end
-
- def program
- return po.nil? ? @program : @po.program
- end
-
- def program= x
- if @po.nil?
- return @program = x
- end
- return @po.program = x
- end
-
- def structure_template
- return po.nil? ? @structure_template : @po.structure_template
- end
+ proxy_accessor :program, :structure_template
- def structure_template= x
- if @po.nil?
- return @structure_template = x
- end
- return @po.structure_template = x
+ def initialize(args={})
+ super args
end
def similar? bc
return false unless bc.kind_of? self.class
- super(bc) and @program == bc.program and @structure_template == bc.structure_template
+ super(bc) and program == bc.program and structure_template == bc.structure_template
end
- def save
- super do
- if @po.nil?
- @po = create_persistent_object(
- :program_schedule => Kernel::ProgramSchedule.active_instance,
- :dtstart => @dtstart,
- :dtend => @dtend,
- :program => @program,
- :structure_template => @structure_template )
- end
- end
- end
- def po!
- if @po.nil?
- @po = create_persistent_object(
- :program_schedule => Kernel::ProgramSchedule.active_instance,
- :dtstart => @dtstart,
- :dtend => @dtend,
- :program => @program,
- :structure_template => @structure_template )
- end
- @po
- end
+ #def save
+ # super do
+ # if @po.nil?
+ # @po = create_persistent_object(
+ # :program_schedule => Kernel::ProgramSchedule.active_instance,
+ # :dtstart => @dtstart,
+ # :dtend => @dtend,
+ # :program => @program,
+ # :structure_template => @structure_template )
+ # end
+ # end
+ #end
end
View
41 scheduler/test/unit/lightweight/original_test.rb
@@ -0,0 +1,41 @@
+require File.dirname(__FILE__) + '/../../test_helper'
+
+NS=RadiaSource::LightWeight
+
+class OrginalTest < ActiveSupport::TestCase
+ fixtures :programs, :structure_templates
+
+
+ def test_proxy_methods
+ assert NS::Original.instance_methods.include? "program"
+ assert NS::Original.instance_methods.include? "program="
+ assert NS::Original.instance_methods.include? "structure_template"
+ assert NS::Original.instance_methods.include? "structure_template="
+ end
+
+ def test_save
+ t = Time.now
+ original = NS::Original.new :dtstart => t, :dtend => t + 30.minutes,
+ :program => Program.first,:structure_template => StructureTemplate.first
+
+ assert original.save
+
+ o2 = Original.find original.po.id
+
+ assert_equal o2.program, original.program
+ end
+
+ def test_similar?
+ orig1 = NS::Original.new_from_persistent_object Original.first
+ orig2 = NS::Original.new_from_persistent_object Original.first
+
+ assert orig1.similar?(orig2)
+
+ # I expect at least 2 structure templates from fixtures!!!
+ orig2.structure_template = StructureTemplate.last
+
+ assert_not_equal orig1.structure_template, orig2.structure_template
+ assert !orig1.similar?(orig2)
+ end
+end
+

0 comments on commit a775c80

Please sign in to comment.
Something went wrong with that request. Please try again.