trailblazer / trailblazer.github.io

The TRAILBLAZER.TO website. Please PR against the f6 branch. 💋
http://trailblazer.to
23 stars 55 forks source link

Broken "params" in guide with Operations/Handling Input #125

Open bbugh opened 6 years ago

bbugh commented 6 years ago

In Operations > 01 > Handling Input it says to add def how_are_you?(options, params:, **) to the method and use BlogPost::Create.( { happy: "yes" } ) to call it. However, I get an error when running the example spec:

     Failure/Error:
           def how_are_you?(options, params:, **)
             puts "How are you?"

             params[:happy] == "yes"
           end

     ArgumentError:
       missing keyword: params

Changing the spec line to this:

result = BlogPost::Create.call(params: { happy: "yes" })

results in a spec test success, but I still don't know if this how it's supposed to work, because Trailblazer::Rails::Controller#run doesn't pass a params key in, it just directly passes the params (presumably to options).

bbugh commented 6 years ago

Looks like since the next section explains the keyword commands, this should just stick with options, * instead and check with options[:happy] == 'yes' and leave the keyword parameter destructuring in the next section?

bbugh commented 6 years ago

Hmmm... I'm definitely confused now. Following the guide has me change the Gemfile, replacing trailblazer-operation with trailblazer which changed the version of trailblazer-operation.

Using trailblazer-operation 0.0.13 (was 0.1.3)

I'm not actually sure what to do with this issue now.

apotonick commented 6 years ago

This is because you're using TRB 2.1 and this guide is still 2.0, since 2.1 hasn't been officially released, yet. :wink:

konung commented 6 years ago

@bbugh I'm guessing you are using TRB 2.1 with Docs for TRB2.0 - which are in the process of being updated right now. params was a positional argument in a step, but just became a keyword argument in TRB 2.1 It's only reflected here right now http://trailblazer.to/blog/2017-12-trailblazer-2-1-what-you-need-to-know.html . Docs shall be updated in the comming weeks.

bbugh commented 6 years ago

Hmm... no, trailblazer is at 2.0.7:

# Gemfile
gem 'trailblazer'
Using trailblazer-operation 0.0.13 <--
Using trailblazer 2.0.7

But if I switch to trailblazer-operation it loads the latest:

# Gemfile
gem 'trailblazer-operation'
Using trailblazer-operation 0.1.3

It looks to me like the gemspec for 2.0.7 is misconfigured?

konung commented 6 years ago

Maybe . I'm still on TRB 2.0.6 :D If you want a "stable" version. TRB 2.1 is stable but hasn't been released officially yet because Docs are not finished. So it's causing confusion. It's a few weeks off.

Meanwhile if you are interested here is my gemspec file for Rails 4.2.10

#  Trailblazer

gem 'reform', '2.2.4'
gem 'reform-rails', '0.1.7'
gem 'dry-validation', '0.11.1'
gem 'dry-types', '0.12.0'
gem 'representable', '3.0.4'
gem 'roar', '1.1.0'
gem 'trailblazer', '2.0.6'
gem 'trailblazer-loader', '0.1.1'
gem "trailblazer-compat", '0.1.0'
gem 'trailblazer-rails', '1.0.2'
gem 'cells', '4.1.7'
gem 'cells-rails', '0.0.8'
gem 'trailblazer-cells', '0.0.3'
gem 'hamlit', '2.3.1'
gem 'cells-hamlit', '0.2.0'
gem 'hamlit-block', '0.3.0'
gem 'kaminari-cells', '1.0.0'
gem 'virtus', '1.0.5' # Legacy compatibility  - for a special use case . Virtus was replaced by dry-trypes/dry-validation. Most people shouldn't need this at all.
gem 'uber', '~> 0.0.15' # https://github.com/trailblazer/trailblazer/issues/144

At this point, I'm in a holding pattern. Once TRB 2.1 is out and I have better test coverage I shall upgrade straight to Rails 5.2 and TRB 2.1. I tried it and for the most part, it worked, but I shall wait to complete writing better tests

konung commented 6 years ago

Trailblazer-compat - is only if you have TRB 1.1 operations - if you have a new app - you shouldn't need it at all.

konung commented 6 years ago

I shall try to setup TRB 2.1 + Rails 5.2 basic starter app and see what happens.

apotonick commented 6 years ago

Hm, weird, it should require the 2.0 operation gem, only. See here: https://github.com/trailblazer/trailblazer/blob/ea564941d04078829f03648a28e2dbf57f194ad6/trailblazer.gemspec#L20

bbugh commented 6 years ago

@apotonick That says ">= 0.0.12", "< 0.1.0". Given the history of releases of trailblazer, (0.1.3, 0.1.2, 0.1.1, 0.0.13, 0.0.12, ...) the largest number greater than 0.0.12 and less than 0.1.0 is 0.0.13.

apotonick commented 6 years ago

Ok, I understand now. It's all correct but you're too fast! :laughing:

We already have the 2.1-compatible operation released since it's been stable for a while. That is 0.1.x. The trailblazer gem is still 2.0 and hence requires the op gem from the 0.0.x line. If you require that one manually, you get the updated version with this better behavior. Makes sense?

apotonick commented 6 years ago

Actually, now I'm thinking about releasing a trailblazer-operation- 2.1.0 so it's less confusing.

bbugh commented 6 years ago

I wish I had a dollar for every time I heard that!

I'm not sure what you mean about being too fast though, I'm just following the guides on the site. It seems like, barring the oddity with the version numbering, this is still actually a bug in the guides. Following them directly to the letter results in this error.