Sha256: cc2949672604e10557501fe69f7bfeb1b2ec8dfa5b44eb56d99f1c1c5d943002

Contents?: true

Size: 1.52 KB

Versions: 8

Compression:

Stored size: 1.52 KB

Contents

require "test_helper"

require "trailblazer/deprecation/context"
require "trailblazer/deprecation/call"

class DeprecationCallTest < Minitest::Spec
  class Create < Trailblazer::Operation
    step :create_model

    def create_model(options, params:, **)
      options["model"] = params.inspect
      options[:user] = options["current_user"]
    end
  end

  it "works with correct style" do
    result = Create.( params: { title: "Hello" } )
    result.inspect(:model, :user, :current_user, :params).must_equal %{<Result:false ["{:title=>\\\"Hello\\\"}", nil, nil, {:title=>\"Hello\"}] >}
  end

  it "works with correct style plus dependencies" do
    result = Create.( params: { title: "Hello" }, current_user: Object )
    result.inspect(:model, :user, :current_user, :params).must_equal %{<Result:true ["{:title=>\\\"Hello\\\"}", Object, Object, {:title=>\"Hello\"}] >}
  end

  it "converts old positional style" do
    result = Create.( { title: "Hello" }, "current_user" => user=Object )
    result.inspect(:model, :user, :current_user, :params).must_equal %{<Result:true ["{:title=>\\\"Hello\\\"}", Object, Object, {:title=>\"Hello\"}] >}
  end

  class WeirdStrongParameters < Hash
  end

  it "converts old positional style with StrongParameters" do
    params = WeirdStrongParameters.new
    params[:title] = "Hello"

    result = Create.( params, "current_user" => user=Object )

    result.inspect(:model, :user, :current_user, :params).must_equal %{<Result:true ["{:title=>\\\"Hello\\\"}", Object, Object, {:title=>\"Hello\"}] >}
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
trailblazer-2.1.0.rc1 test/deprecation/call_test.rb
trailblazer-2.1.0.beta7 test/deprecation/call_test.rb
trailblazer-2.1.0.beta6 test/deprecation/call_test.rb
trailblazer-2.1.0.beta5 test/deprecation/call_test.rb
trailblazer-2.1.0.beta4 test/deprecation/call_test.rb
trailblazer-2.1.0.beta3 test/deprecation/call_test.rb
trailblazer-2.1.0.beta2 test/deprecation/call_test.rb
trailblazer-2.1.0.beta1 test/deprecation/call_test.rb