lib/scaffolding/transformer.rb in bullet_train-super_scaffolding-1.0.40 vs lib/scaffolding/transformer.rb in bullet_train-super_scaffolding-1.0.41
- old
+ new
@@ -351,11 +351,11 @@
def scaffold_replace_line_in_file(file, content, in_place_of)
file = transform_string(file)
# we specifically don't transform the content, we assume a builder function created this content.
in_place_of = transform_string(in_place_of)
- Scaffolding::FileManipulator.replace_line_in_file(file, content, in_place_of)
+ Scaffolding::FileManipulator.replace_line_in_file(file, content, in_place_of, suppress_could_not_find: suppress_could_not_find)
end
# if class_name isn't specified, we use `child`.
# if class_name is specified, then `child` is assumed to be a parent of `class_name`.
# returns an array with the ability line and a boolean indicating whether the ability line should be inserted among
@@ -1045,18 +1045,18 @@
scaffold_add_line_to_file("./app/views/account/scaffolding/completely_concrete/tangible_things/_tangible_thing.json.jbuilder", ":#{name},", RUBY_NEW_FIELDS_HOOK, prepend: true, suppress_could_not_find: true)
scaffold_add_line_to_file("./app/serializers/api/v1/scaffolding/completely_concrete/tangible_thing_serializer.rb", ":#{name},", RUBY_NEW_FIELDS_HOOK, prepend: true) unless type == "file_field"
assertion = case type
when "date_field"
- "assert_equal Date.parse(tangible_thing_data['#{name}']), tangible_thing.#{name}"
+ "assert_equal_or_nil Date.parse(tangible_thing_data['#{name}']), tangible_thing.#{name}"
when "date_and_time_field"
- "assert_equal DateTime.parse(tangible_thing_data['#{name}']), tangible_thing.#{name}"
+ "assert_equal_or_nil DateTime.parse(tangible_thing_data['#{name}']), tangible_thing.#{name}"
when "file_field"
# TODO: If we want to use Cloudinary to handle our files, we should make sure we're getting a URL.
"assert tangible_thing_data['#{name}'].match?('foo.txt') unless response.status == 201"
else
- "assert_equal tangible_thing_data['#{name}'], tangible_thing.#{name}"
+ "assert_equal_or_nil tangible_thing_data['#{name}'], tangible_thing.#{name}"
end
scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb", assertion, RUBY_NEW_FIELDS_HOOK, prepend: true)
end
# File fields are handled in a specific way when using the jsonapi-serializer.
@@ -1083,10 +1083,24 @@
unless attribute_options[:readonly]
scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb", "#{name}: #{attribute_assignment},", RUBY_ADDITIONAL_NEW_FIELDS_HOOK, prepend: true)
scaffold_add_line_to_file("./test/controllers/api/v1/scaffolding/completely_concrete/tangible_things_endpoint_test.rb", "assert_equal @tangible_thing.#{name}, #{attribute_assignment}", RUBY_EVEN_MORE_NEW_FIELDS_HOOK, prepend: true)
end
end
+
+ # We need to update our new Tangible Thing's
+ # jbuilder files if it's scoped under "account".
+ # TODO: Should we run this if `namespace.present?` instead?
+ if namespace == "account"
+ target_string = "#{transform_string("scaffolding/completely_concrete/tangible_things")}/#{transform_string("tangible_thing")}"
+ replacement_string = "#{namespace}/#{target_string}"
+ [
+ "app/views/account/completely_concrete/tangible_things/index.json.jbuilder",
+ "app/views/account/completely_concrete/tangible_things/show.json.jbuilder"
+ ].each do |path|
+ scaffold_replace_line_in_file(path, replacement_string, target_string)
+ end
+ end
end
#
# MODEL ASSOCATIONS
#
@@ -1420,11 +1434,12 @@
retry
end
begin
routes_manipulator.apply([routes_namespace])
- rescue
- add_additional_step :yellow, "We weren't able to automatically add your `#{routes_namespace}` routes for you. In theory this should be very rare, so if you could reach out on Slack, you could probably provide context that will help us fix whatever the problem was. In the meantime, to add the routes manually, we've got a guide at https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/ ."
+ rescue => e
+ puts "We weren't able to automatically add your `#{routes_namespace}` routes for you. In theory this should be very rare, so if you could reach out on Slack, you could probably provide context that will help us fix whatever the problem was. In the meantime, to add the routes manually, we've got a guide at https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/ .".send(:yellow)
+ raise e
end
Scaffolding::FileManipulator.write("config/routes.rb", routes_manipulator.lines)
end