From 33613c8f6c867c8d77044f431fb912ad29322a6f Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Tue, 14 May 2024 18:23:58 -0500 Subject: [PATCH] Chomp the plain method accessor test, not too sure if we need it --- .../associated/associated_generator.rb | 26 ++----------------- .../generators/associated_generator_test.rb | 8 +----- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/lib/generators/associated/associated_generator.rb b/lib/generators/associated/associated_generator.rb index a62eec0..1de9f32 100644 --- a/lib/generators/associated/associated_generator.rb +++ b/lib/generators/associated/associated_generator.rb @@ -1,15 +1,6 @@ class AssociatedGenerator < Rails::Generators::NamedBase source_root File.expand_path("templates", __dir__) - class MissingRecordError < StandardError - attr_reader :record_klass - - def initialize(record_klass) - @record_klass = record_klass - super "Record class '#{record_klass}' could not be found" - end - end - def generate_associated_object template "associated.rb", associated_object_file end @@ -19,26 +10,13 @@ def generate_associated_object_test end def connect_associated_object - raise MissingRecordError.new(record_file) unless File.exist?(record_file) + raise "Record class '#{record_klass}' does not exist" unless File.exist?(record_file) - inject_into_class record_file, record_klass.to_s do + inject_into_class record_file, record_klass do indent "has_object :#{singular_name}\n\n" end end - def connect_associated_object_test - raise MissingRecordError.new(record_test_file) unless File.exist?(record_test_file) - - inject_into_file record_test_file, before: /end\s\z/ do - indent <<~RUBY - - test "works with associated object" do - skip "Pending" - end - RUBY - end - end - private def record_file = "#{destination_root}/app/models/#{record_path}.rb" diff --git a/test/lib/generators/associated_generator_test.rb b/test/lib/generators/associated_generator_test.rb index 0dc481a..eb7141c 100644 --- a/test/lib/generators/associated_generator_test.rb +++ b/test/lib/generators/associated_generator_test.rb @@ -43,14 +43,8 @@ class Organization RUBY end - test "adds parent object connection test" do - run_generator - - assert_file "test/models/organization_test.rb", /\s\stest "works with associated object" do/ - end - test "raises error if associated parent doesn't exist" do - assert_raise AssociatedGenerator::MissingRecordError do + assert_raise RuntimeError do run_generator %w[business monkey] end end