test/operation_test.rb in trailblazer-0.3.3 vs test/operation_test.rb in trailblazer-1.0.0.rc1
- old
+ new
@@ -199,18 +199,18 @@
# unlimited arguments for ::run and friends.
- class OperationReceivingLottaArguments < Trailblazer::Operation
- def process(model, params)
- @model = [model, params]
- end
- include Inspect
- end
+ # class OperationReceivingLottaArguments < Trailblazer::Operation
+ # def process(model, params)
+ # @model = [model, params]
+ # end
+ # include Inspect
+ # end
- it { OperationReceivingLottaArguments.run(Object, {}).to_s.must_equal %{[true, <OperationReceivingLottaArguments @model=[Object, {}]>]} }
+ # it { OperationReceivingLottaArguments.run(Object, {}).to_s.must_equal %{[true, <OperationReceivingLottaArguments @model=[Object, {}]>]} }
# ::present only runs #setup! which runs #model!.
class ContractOnlyOperation < Trailblazer::Operation
self.contract_class = class Contract
def initialize(model)
@@ -228,77 +228,9 @@
raise "This is not run!"
end
end
it { ContractOnlyOperation.present({}).contract._model.must_equal Object }
-end
-
-
-class OperationBuilderTest < MiniTest::Spec
- class ParentOperation < Trailblazer::Operation
- def process(params)
- end
-
- class Sub < self
- end
-
- builds do |params|
- Sub if params[:sub]
- end
- end
-
- it { ParentOperation.run({}).last.class.must_equal ParentOperation }
- it { ParentOperation.run({sub: true}).last.class.must_equal ParentOperation::Sub }
- it { ParentOperation.({}).class.must_equal ParentOperation }
- it { ParentOperation.({sub: true}).class.must_equal ParentOperation::Sub }
-end
-
-
-# ::contract builds Reform::Form class
-class OperationInheritanceTest < MiniTest::Spec
- class Operation < Trailblazer::Operation
- contract do
- property :title
- property :band
-
- # TODO/DISCUSS: this is needed in order to "handle" the anon forms. but in Trb, that
- # doesn't really matter as AM is automatically included?
- def self.name
- "Song"
- end
- end
-
- class JSON < self
- # inherit Contract
- contract do
- property :genre, validates: {presence: true}
- property :band, virtual: true
- end
- end
- end
-
- # inherits subclassed Contract.
- it { Operation.contract_class.wont_equal Operation::JSON.contract_class }
-
- it do
- form = Operation.contract_class.new(OpenStruct.new)
- form.validate({})#.must_equal true
- form.errors.to_s.must_equal "{}"
-
- form = Operation::JSON.contract_class.new(OpenStruct.new)
- form.validate({})#.must_equal true
- form.errors.to_s.must_equal "{:genre=>[\"can't be blank\"]}"
- end
-
- # allows overriding options
- it do
- form = Operation::JSON.contract_class.new(song = OpenStruct.new)
- form.validate({genre: "Punkrock", band: "Osker"}).must_equal true
- form.sync
-
- song.genre.must_equal "Punkrock"
- song.band.must_equal nil
- end
end
class OperationErrorsTest < MiniTest::Spec
class Operation < Trailblazer::Operation
\ No newline at end of file