我沿着Trailblazer的书来跟我学习一些开拓者。昨天,我的所有测试都是绿色的。今天,我今天尝试添加rails-timeago
帮助器,我遇到了一些麻烦,但我最终设法修复了。在宝石工作之后,我重新运行了现有的测试,令我惊讶的是,所有的都是红色的,并且现有的操作都应该受到责备。
我打开了一个rails控制台来测试我的操作,所以我做了一个Create.
,它确实在那里失败了。我的想法已经不多了,Google也没有特别帮我。
这是错误代码(在rails控制台上):
irb(main):004:0> Thing::Create.(thing: {name: 'Rails', description: 'Kiackass web app'}) #: undefined method `class_builder' for Thing::Create:Class Did you mean? class_attribute from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/trailblazer-1.1.1/lib/trailblazer/operation/builder.rb:20:in `build_operation_class' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/trailblazer-1.1.1/lib/trailblazer/operation/builder.rb:24:in `build_operation' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/trailblazer-1.1.1/lib/trailblazer/operation.rb:34:in `call' from (irb):4 from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console.rb:65:in `start' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/console_helper.rb:9:in `start' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:78:in `console' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!' from C:/Ruby23-x64/lib/ruby/gems/2.3.0/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `' from bin/rails:4:in `require' from bin/rails:4:in `'
这是我目前的宝石文件:
source 'https://rubygems.org'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem "sass-rails"
gem "uglifier"
gem "coffee-rails"
gem "jquery-rails"
gem "foundation-rails"
gem "haml-rails"
gem "simple_form"
gem "therubyracer", :platform=>:ruby
gem "thin"
gem "sqlite3"
group :development do
gem "binding_of_caller", :platforms=>[:mri_21]
gem "rails_layout"
end
gem "responders"
group :development, :test do
gem "minitest-rails-capybara"
gem "minitest-line"
gem "minitest-reporters"
gem "win32console"
end
group :test do
gem 'memory_test_fix'
end
group :production do
gem "rails_12factor"
end
gem "reform"
# gem "reform", github: "apotonick/reform", branch: "reform-2"
#gem "reform", path: "../reform"
# gem "representable", path: "../representable"
gem "representable"
# gem "reform", "2.0.4"
# gem "disposable", github: "apotonick/disposable"
gem "virtus"
# gem "disposable", path: "../disposable"
gem "tyrant"
# gem "tyrant", path: "../tyrant"
gem "trailblazer"
gem "trailblazer-loader"
gem "trailblazer-rails"
# gem "trailblazer", path: "../trailblazer"
# gem "trailblazer-loader", path: "../trailblazer-loader"
# gem "trailblazer-rails", path: "../trailblazer-rails"
# gem "disposable", path: "../disposable"
# gem "trailblazer-rails", ">= 0.1.3"
# gem "cells", git: "https://github.com/apotonick/cells"
# gem "cells", path: "../cells"
gem "cells"
gem "cells-haml"
gem "haml", github: "haml/haml", ref: "7c7c169"
gem "kaminari-cells"
gem "paperdragon"
gem "file_validators"
# gem "roar", path: "../roar" #"1.0.0"
gem "roar"
gem "pundit"
gem "rails-timeago"
gem "email_validator"
gem "foundation-icons-sass-rails"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
这是运营商的代码:
class Thing < ActiveRecord::Base
class Create < Trailblazer::Operation
include Model
model Thing, :create
contract do
property :name
property :description
validates :name, presence: true
validates :description, length: {in: 4..160}, allow_blank: true
end
def process(params)
validate(params[:thing]) do |f|
f.save
end
end
end
class Update < Create
action :update
contract do
property :name, writeable: false
end
end
end
这是我的一些测试的代码:
require 'test_helper'
class ThingCrudTest < Minitest::Spec
describe "Create" do
it "persists valid" do
thing = Thing::Create.(thing: {name: 'Rails', description: 'Kickass web dev'}).model
thing.persisted?.must_equal true
thing.name.must_equal 'Rails'
thing.description.must_equal "Kickass web dev"
end
it "invalid name" do
res, op = Thing::Create.run(thing: {name: ""})
res.must_equal false
op.model.persisted?.must_equal false
op.contract.errors.to_s.must_equal "{:name=>[\"can't be blank\"]}"
end
it "invalid description" do
res, op = Thing::Create.run(thing: {name: "Rails", description: "hi"})
res.must_equal false
op.contract.errors.to_s.must_equal"{:description=>[\"is too short (minimum is 4 characters)\"]}"
end
end
describe "Update" do
let (:thing) do
Thing::Create.(thing: {name: "Rails", description: "Kickass web dev"}).model
end
it "persists valid, ignores name" do
new_thing = Thing::Update.(id: thing.id, thing: {name: "Rails", description: "Simply better"}).model
new_thing.name.must_equal "Rails"
new_thing.description.must_equal "Simply better"
end
end
end
这是测试的输出:
Started with run options --seed 46307 ERROR["test_0002_invalid name", #, 0.00465575500857085]? test_0002_invalid name#Create (0.01s) NoMethodError: NoMethodError: undefined method `class_builder' for Thing::Create:Class Did you mean? class_attribute test/concepts/thing/crud_test.rb:14:in `block (2 levels) in ' ERROR["test_0001_persists valid", #, 0.0119611140107736] test_0001_persists valid#Create (0.01s) NoMethodError: NoMethodError: undefined method `class_builder' for Thing::Create:Class Did you mean? class_attribute test/concepts/thing/crud_test.rb:6:in `block (2 levels) in ' ERROR["test_0003_invalid description", #, 0.019230154925026] test_0003_invalid description#Create (0.02s) NoMethodError: NoMethodError: undefined method `class_builder' for Thing::Create:Class Did you mean? class_attribute test/concepts/thing/crud_test.rb:22:in `block (2 levels) in ' ERROR["test_0001_persists valid, ignores name", #, 0.031214163987897336] test_0001_persists valid, ignores name#Update (0.03s) NoMethodError: NoMethodError: undefined method `class_builder' for Thing::Create:Class Did you mean? class_attribute test/concepts/thing/crud_test.rb:31:in `block (2 levels) in ' test/concepts/thing/crud_test.rb:35:in `block (2 levels) in ' ERROR["test_0001_allows anonymous", ThingIntegrationTest, 0.06196290999650955] test_0001_allows anonymous#ThingIntegrationTest (0.06s) NoMethodError: NoMethodError: undefined method `class_builder' for Thing::Create:Class Did you mean? class_attribute app/controllers/things_controller.rb:3:in `new' test/integration/thing_test.rb:5:in `block in ' 5/5: [===================================] 100% Time: 00:00:00, Time: 00:00:00 Finished in 0.07067s 5 tests, 0 assertions, 0 failures, 5 errors, 0 skips
这是gem list
的粗略内容供参考。
*** LOCAL GEMS *** actioncable (5.0.0.1) actionmailer (5.0.0.1, 4.2.7.1) actionpack (5.0.0.1, 4.2.7.1) actionview (5.0.0.1, 4.2.7.1) activejob (5.0.0.1, 4.2.7.1) activemodel (5.0.0.1, 4.2.7.1) activerecord (5.0.0.1, 4.2.7.1) activesupport (5.0.0.1, 4.2.7.1, 4.2.4) acts_as_commentable (4.0.2) addressable (2.5.0) ansi (1.5.0) arel (7.1.4, 7.1.3, 6.0.3) ast (2.3.0) autoprefixer-rails (6.5.3, 6.5.0.2, 6.4.0.3) aws-sdk-core (2.6.6) axiom-types (0.1.1) babel-source (5.8.35) babel-transpiler (0.7.0) bcrypt (3.1.11 ruby x64-mingw32, 3.1.7 x64-mingw32) better_errors (2.1.1) bigdecimal (default: 1.2.8) binding_of_caller (0.7.2) bootstrap-form (3.0.0) bootstrap-glyphicons (0.0.1) bootstrap-sass (3.3.7) bootstrap-will_paginate (0.0.10) bootstrap_form (2.5.2) builder (3.2.2) bundler (1.13.6, 1.13.2) byebug (9.0.6, 8.2.1) capybara (2.11.0, 2.10.2, 2.10.1) cells (4.1.5, 4.1.4, 4.1.3) cells-haml (0.0.10) cells-rails (0.0.6) city-state (0.0.13) coderay (1.1.1) coercible (1.0.0) coffee-rails (4.2.1) coffee-script (2.4.1) coffee-script-source (1.11.1, 1.10.0) concurrent-ruby (1.0.2, 1.0.0) daemons (1.2.4) database_cleaner (1.5.3, 1.5.2) debug_inspector (0.0.2) declarative (0.0.8) descendants_tracker (0.0.4) did_you_mean (1.0.0) disposable (0.3.2) docile (1.1.5) dotenv (2.1.1) dragonfly (1.0.12) dry-configurable (0.3.0) dry-container (0.5.0) dry-core (0.2.1) dry-equalizer (0.2.0) dry-logic (0.4.0) dry-types (0.9.2) dry-validation (0.10.3) email_validator (1.6.0) equalizer (0.0.11) erubis (2.7.0) eventmachine (1.2.1 x64-mingw32) execjs (2.7.0, 2.6.0) faker (1.4.2) ffi (1.9.14 x64-mingw32) file_validators (2.1.0) formatador (0.2.5) foundation-icons-sass-rails (3.0.0) foundation-rails (6.2.4.0) globalid (0.3.7) glyphicons-rails (0.1.2) guard (2.13.0) guard-compat (1.2.1) guard-minitest (2.4.4) haml (4.0.7) haml-lint (0.999.999) haml-rails (0.9.0) haml_lint (0.18.4) hanami (0.9.1) hanami-assets (0.4.0) hanami-controller (0.8.0) hanami-helpers (0.5.0) hanami-mailer (0.4.0) hanami-model (0.7.0) hanami-router (0.8.1) hanami-utils (0.9.1) hanami-validations (0.7.1) hanami-view (0.8.0) hoe (3.15.2) hoe-bundler (1.3.0) hpricot (0.8.6) html2haml (1.0.1) http_router (0.11.2) httparty (0.13.7) i18n (0.7.0) ice_nine (0.11.2) inflecto (0.0.2) io-console (default: 0.4.5) jbuilder (2.6.1, 2.6.0, 2.4.1) jmespath (1.3.1, 1.2.4) jquery-rails (4.2.1, 4.1.1) json (default: 1.8.3) json_pure (1.8.3) kaminari (0.17.0) kaminari-cells (0.0.4) listen (3.0.8) loofah (2.0.3) lumberjack (1.0.10) mail (2.6.4, 2.6.3) memory_test_fix (1.4.0, 1.3.0) method_source (0.8.2) mime-types (3.1, 2.99) mime-types-data (3.2016.0521) mini_portile (0.6.2) mini_portile2 (2.1.0, 2.0.0) minitest (5.10.1, 5.9.1, 5.8.4, 5.8.3) minitest-capybara (0.8.2) minitest-line (0.6.3) minitest-metadata (0.6.0) minitest-rails (3.0.0, 2.2.1) minitest-rails-capybara (3.0.0, 2.1.2) minitest-reporters (1.1.13, 1.1.12, 1.1.9) minitest-spec-rails (5.4.0) multi_json (1.12.1, 1.11.2) multi_xml (0.5.5) mysql2 (0.4.4 x64-mingw32, 0.4.2 x64-mingw32) nenv (0.3.0) nested_form (0.3.2) net-telnet (0.1.1) nio4r (1.2.1) nokogiri (1.6.8.1 x64-mingw32) notiffany (0.1.1) orm_adapter (0.5.0) paperdragon (0.0.11) parser (2.3.3.1) pg (0.19.0 x64-mingw32, 0.17.1 x64-mingw32) power_assert (0.2.6) powerpack (0.1.1) pry (0.10.4) psych (default: 2.0.17) public_suffix (2.0.4) puma (3.6.2, 3.6.0, 3.4.0) pundit (1.1.0) quiet_assets (1.1.0) rack (2.0.1, 1.6.5, 1.6.4) rack-test (0.6.3) rails (5.0.0.1, 4.2.7.1) rails-assets-datatables.net (1.10.12, 1.10.10) rails-assets-jquery (3.1.1, 2.2.0) rails-controller-testing (0.1.1) rails-deprecated_sanitizer (1.0.3) rails-dom-testing (2.0.1, 1.0.7) rails-html-sanitizer (1.0.3) rails-timeago (2.15.0) rails_12factor (0.0.3, 0.0.2) rails_layout (1.0.34) rails_serve_static_assets (0.0.5, 0.0.4) rails_stdout_logging (0.0.5, 0.0.4) railties (5.0.0.1, 4.2.7.1) rainbow (2.1.0) rake (12.0.0, 11.3.0, 10.5.0, 10.4.2) rake-compiler (0.9.9) rake-compiler-dock (0.5.3) rb-fsevent (0.9.7) rb-inotify (0.9.7) rdoc (4.2.2, default: 4.2.1) reform (2.2.3, 2.2.2) reform-rails (0.1.7) representable (3.0.2, 3.0.1) responders (2.3.0) roar (0.12.7) rom (2.0.2) rom-mapper (0.4.0) rom-repository (0.3.1) rom-sql (0.9.0) rom-support (2.0.0) rubocop (0.46.0) ruby-progressbar (1.8.1) ruby_parser (3.1.3) rubyzip (1.2.0) sass (3.4.22, 3.4.21) sass-rails (5.0.6) sdoc (0.4.2, 0.4.1) sequel (4.40.0) sexp_processor (4.7.0) shellany (0.0.1) shotgun (0.9.2) simple_form (3.3.1) simplecov (0.12.0, 0.11.1) simplecov-html (0.10.0) slop (3.6.0) spring (1.7.2, 1.6.2) spring-watcher-listen (2.0.0) sprockets (3.7.0, 3.5.2) sprockets-es6 (0.9.2) sprockets-rails (3.2.0) sqlite3 (1.3.12 x64-mingw32, 1.3.11 x64-mingw32) sqlite3-ruby (1.3.3) sysexits (1.2.0) test-unit (3.1.5) thin (1.7.0) thor (0.19.4, 0.19.1) thread_safe (0.3.5) tilt (2.0.5, 2.0.2) timeago-rails (0.1.5) trailblazer (1.1.2, 1.1.1) trailblazer-loader (0.1.0) trailblazer-rails (0.4.0) transproc (0.4.1) turbolinks (5.0.1) turbolinks-source (5.0.0) tyrant (0.0.3) tzinfo (1.2.2) tzinfo-data (1.2016.10, 1.2016.9, 1.2016.8, 1.2016.7) uber (0.1.0, 0.0.15) uglifier (3.0.4, 3.0.3, 3.0.2, 3.0.0, 2.7.2) unicode-display_width (1.1.1) url_mount (0.2.1) virtus (1.0.5) warden (1.2.6) web-console (3.4.0, 3.3.1, 3.1.1) websocket-driver (0.6.4) websocket-extensions (0.1.2) will_paginate (3.0.7) win32console (1.3.2) wisper (1.6.1) xpath (2.0.0)
我确信自昨天以来我没有触及过操作员的代码或任何可能破坏它的东西;我目前正在研究一个细胞。我现在已多次运行bundle install
和bundle update
。再说一遍,由于所有这一切都是按照预期的方式运作,我愿意责备一些宝石诡计,但我仍然可以得到任何帮助。