Skip to content

Commit

Permalink
Chomp the plain method accessor test, not too sure if we need it
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspth committed May 14, 2024
1 parent 226e11c commit 33613c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 31 deletions.
26 changes: 2 additions & 24 deletions lib/generators/associated/associated_generator.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down
8 changes: 1 addition & 7 deletions test/lib/generators/associated_generator_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 33613c8

Please sign in to comment.