From cf3ff4ba4a6cc5ec6482d4e052af9409cd403b85 Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Fri, 20 Mar 2020 13:12:55 -0600 Subject: [PATCH 1/2] rename gem to view_component --- actionview-component.gemspec => view_component.gemspec | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) rename actionview-component.gemspec => view_component.gemspec (84%) diff --git a/actionview-component.gemspec b/view_component.gemspec similarity index 84% rename from actionview-component.gemspec rename to view_component.gemspec index 3e09bbc2f..a1b308d04 100644 --- a/actionview-component.gemspec +++ b/view_component.gemspec @@ -6,12 +6,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "view_component/version" Gem::Specification.new do |spec| - spec.name = "actionview-component" + spec.name = "view_component" spec.version = ViewComponent::VERSION::STRING spec.authors = ["GitHub Open Source"] spec.email = ["opensource+view_component@github.com"] - spec.summary = %q{MOVED to view_component.} + spec.summary = %q{View components for Rails} spec.homepage = "https://github.com/github/view_component" spec.license = "MIT" @@ -42,6 +42,4 @@ Gem::Specification.new do |spec| spec.add_development_dependency "better_html", "~> 1" spec.add_development_dependency "rubocop", "= 0.74" spec.add_development_dependency "rubocop-github", "~> 0.13.0" - - spec.post_install_message = "WARNING: actionview-component has been renamed to view_component, and will no longer be published in this namespace. Please update your Gemfile to use view_component." end From 58be3102b1673ea6c2c9570fd4c74d4b1f0a6981 Mon Sep 17 00:00:00 2001 From: Joel Hawksley Date: Fri, 20 Mar 2020 13:13:20 -0600 Subject: [PATCH 2/2] Release v2.0.0 --- CHANGELOG.md | 12 +++++ CONTRIBUTING.md | 6 +-- Gemfile.lock | 4 +- README.md | 21 +++++---- ...oller.rb => view_components_controller.rb} | 2 +- lib/action_view/component.rb | 4 -- lib/action_view/component/base.rb | 13 ------ lib/action_view/component/preview.rb | 8 ---- lib/action_view/component/railtie.rb | 3 -- lib/action_view/component/test_case.rb | 9 ---- lib/action_view/component/test_helpers.rb | 17 ------- .../templates/rails/components/index.html.erb | 4 +- .../rails/components/previews.html.erb | 2 +- lib/view_component.rb | 14 ------ lib/view_component/base.rb | 2 +- lib/view_component/conversion.rb | 9 ---- lib/view_component/engine.rb | 30 ++++++------ lib/view_component/previewable.rb | 4 +- lib/view_component/render_monkey_patch.rb | 20 +------- lib/view_component/rendering_monkey_patch.rb | 2 +- lib/view_component/version.rb | 4 +- .../components/action_view_component.html.erb | 1 - test/app/components/action_view_component.rb | 7 --- test/app/components/post_component.html.erb | 1 - test/app/components/post_component.rb | 7 --- test/app/components/validations_component.rb | 8 +++- .../integration_examples/component.html.erb | 1 - .../integration_examples/deprecated.html.erb | 1 - test/config/application.rb | 2 +- test/config/environments/test.rb | 4 +- test/config/routes.rb | 1 - test/invalid_components_test_helper.rb | 11 ----- .../previews/action_view_component_preview.rb | 9 ---- .../action_view_component_test.rb | 46 ------------------- test/view_component/integration_test.rb | 21 +++------ .../view_component/invalid_components_test.rb | 2 +- test/view_component/preview_test.rb | 6 +-- 37 files changed, 75 insertions(+), 243 deletions(-) rename app/controllers/rails/{components_controller.rb => view_components_controller.rb} (96%) delete mode 100644 lib/action_view/component.rb delete mode 100644 lib/action_view/component/base.rb delete mode 100644 lib/action_view/component/preview.rb delete mode 100644 lib/action_view/component/railtie.rb delete mode 100644 lib/action_view/component/test_case.rb delete mode 100644 lib/action_view/component/test_helpers.rb delete mode 100644 lib/view_component/conversion.rb delete mode 100644 test/app/components/action_view_component.html.erb delete mode 100644 test/app/components/action_view_component.rb delete mode 100644 test/app/components/post_component.html.erb delete mode 100644 test/app/components/post_component.rb delete mode 100644 test/app/views/integration_examples/component.html.erb delete mode 100644 test/app/views/integration_examples/deprecated.html.erb delete mode 100644 test/invalid_components_test_helper.rb delete mode 100644 test/test/components/previews/action_view_component_preview.rb delete mode 100644 test/view_component/action_view_component_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index cf7053526..33014c2d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # master +# v2.0.0 + +* Move to `ViewComponent` namespace, removing all references to `ActionView`. + + * The gem name is now `view_component`. + * ViewComponent previews are now accessed at `/rails/view_components`. + * ViewComponents can _only_ be rendered with the instance syntax: `render(MyComponent.new)`. Support for all other syntaxes has been removed. + * ActiveModel::Validations have been removed. ViewComponent generators no longer include validations. + * In Rails 6.1, no monkey patching is used. + * `to_component_class` has been removed. + * All gem configuration is now in `config.view_component`. + # v1.17.0 * Support Ruby 2.4 in CI. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f04d9d5e..50c65f525 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -34,13 +34,13 @@ Here are a few things you can do that will increase the likelihood of your pull If you are the current maintainer of this gem: 1. Create a branch for the release: `git checkout -b release-vxx.xx.xx` -1. Bump gem version in `lib/action_view/component/version.rb`. Try to adhere to SemVer. +1. Bump gem version in `lib/view_component/version.rb`. Try to adhere to SemVer. 1. Add version heading/entries to `CHANGELOG.md`. 1. Make sure your local dependencies are up to date: `bundle` 1. Ensure that tests are green: `bundle exec rake` 1. Make a PR to github/view_component. -1. Build a local gem: `gem build actionview-component.gemspec` +1. Build a local gem: `gem build view_component.gemspec` 1. Merge github/view_component PR 1. Tag and push: `git tag vx.xx.xx; git push --tags` 1. Create a GitHub release with the pushed tag (https://github.com/github/view_component/releases/new) and populate it with a list of the commits from `git log --pretty=format:"- %s" --reverse refs/tags/[OLD TAG]...refs/tags/[NEW TAG]` -1. Push to rubygems.org -- `gem push actionview-component-VERSION.gem` +1. Push to rubygems.org -- `gem push view_component-VERSION.gem` diff --git a/Gemfile.lock b/Gemfile.lock index e5da354d3..681f189e8 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - actionview-component (1.17.0) + view_component (2.0.0) capybara (~> 3) GEM @@ -187,7 +187,6 @@ PLATFORMS ruby DEPENDENCIES - actionview-component! better_html (~> 1) bundler (~> 1.14) haml (~> 5) @@ -197,6 +196,7 @@ DEPENDENCIES rubocop (= 0.74) rubocop-github (~> 0.13.0) slim (~> 4.0) + view_component! BUNDLED WITH 1.17.3 diff --git a/README.md b/README.md index 8770551da..f53951c12 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ This gem is in the process of a name / API change from `ActionView::Component` t ### How to migrate to ViewComponent -1. In `application.rb`, require `view_component/engine` +1. Update `Gemfile` to use `view_component`. +1. In `application.rb`, require `view_component/engine`. 1. Update components to inherit from `ViewComponent::Base`. 1. Update component tests to inherit from `ViewComponent::TestCase`. 1. Update component previews to inherit from `ViewComponent::Preview`. @@ -33,14 +34,14 @@ This library is designed to integrate as seamlessly as possible with Rails, with ## Compatibility -`actionview-component` is tested for compatibility with combinations of Ruby `2.4`/`2.5`/`2.6`/`2.7` and Rails `5.0.0`/`5.2.3`/`6.0.0`/`master`. +`view_component` is tested for compatibility with combinations of Ruby `2.4`/`2.5`/`2.6`/`2.7` and Rails `5.0.0`/`5.2.3`/`6.0.0`/`master`. ## Installation In `Gemfile`, add: ```ruby -gem "actionview-component" +gem "view_component" ``` In `config/application.rb`, add: @@ -322,9 +323,9 @@ class TestComponentPreview < ViewComponent::Preview end ``` -Which generates , -, -and . +Which generates , +, +and . The `ViewComponent::Preview` base class includes [`ActionView::Helpers::TagHelper`][tag-helper], which provides the [`tag`][tag] @@ -351,7 +352,7 @@ To use `lib/component_previews`: `config/application.rb` ```ruby -config.action_view_component.preview_path = "#{Rails.root}/lib/component_previews" +config.view_component.preview_path = "#{Rails.root}/lib/component_previews" ``` #### Configuring TestController @@ -360,7 +361,7 @@ Component tests and previews assume the existence of an `ApplicationController` `config/application.rb` ```ruby -config.action_view_component.test_controller = "BaseController" +config.view_component.test_controller = "BaseController" ``` ### Setting up RSpec @@ -382,7 +383,7 @@ To use component previews: `config/application.rb` ```ruby -config.action_view_component.preview_path = "#{Rails.root}/spec/components/previews" +config.view_component.preview_path = "#{Rails.root}/spec/components/previews" ``` ## Frequently Asked Questions @@ -418,7 +419,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/github ## Contributors -`actionview-component` is built by: +`view_component` is built by: |joelhawksley|tenderlove|jonspalmer|juanmanuelramallo|vinistock| |:---:|:---:|:---:|:---:|:---:| diff --git a/app/controllers/rails/components_controller.rb b/app/controllers/rails/view_components_controller.rb similarity index 96% rename from app/controllers/rails/components_controller.rb rename to app/controllers/rails/view_components_controller.rb index cba635fd3..2cd32c4d6 100644 --- a/app/controllers/rails/components_controller.rb +++ b/app/controllers/rails/view_components_controller.rb @@ -2,7 +2,7 @@ require "rails/application_controller" -class Rails::ComponentsController < Rails::ApplicationController # :nodoc: +class Rails::ViewComponentsController < Rails::ApplicationController # :nodoc: prepend_view_path File.expand_path("../../../lib/railties/lib/rails/templates/rails", __dir__) prepend_view_path "#{Rails.root}/app/views/" if defined?(Rails.root) diff --git a/lib/action_view/component.rb b/lib/action_view/component.rb deleted file mode 100644 index 6613d33b6..000000000 --- a/lib/action_view/component.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -require "active_model" -require "view_component" diff --git a/lib/action_view/component/base.rb b/lib/action_view/component/base.rb deleted file mode 100644 index 8effad9d0..000000000 --- a/lib/action_view/component/base.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -module ActionView - module Component - class Base < ViewComponent::Base - include ActiveModel::Validations - - def before_render_check - validate! - end - end - end -end diff --git a/lib/action_view/component/preview.rb b/lib/action_view/component/preview.rb deleted file mode 100644 index c16bd1e45..000000000 --- a/lib/action_view/component/preview.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -module ActionView - module Component # :nodoc: - class Preview < ViewComponent::Preview - end - end -end diff --git a/lib/action_view/component/railtie.rb b/lib/action_view/component/railtie.rb deleted file mode 100644 index 312a96880..000000000 --- a/lib/action_view/component/railtie.rb +++ /dev/null @@ -1,3 +0,0 @@ -# frozen_string_literal: true - -require "view_component/engine" diff --git a/lib/action_view/component/test_case.rb b/lib/action_view/component/test_case.rb deleted file mode 100644 index ef937fabc..000000000 --- a/lib/action_view/component/test_case.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module ActionView - module Component - class TestCase - include ActionView::Component::TestHelpers - end - end -end diff --git a/lib/action_view/component/test_helpers.rb b/lib/action_view/component/test_helpers.rb deleted file mode 100644 index f32705309..000000000 --- a/lib/action_view/component/test_helpers.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module ActionView - module Component - module TestHelpers - include ViewComponent::TestHelpers - - def render_component(component, **args, &block) - ActiveSupport::Deprecation.warn( - "`render_component` has been deprecated in favor of `render_inline`, and will be removed in v2.0.0." - ) - - render_inline(component, args, &block) - end - end - end -end diff --git a/lib/railties/lib/rails/templates/rails/components/index.html.erb b/lib/railties/lib/rails/templates/rails/components/index.html.erb index b3da9a73b..2e2f60f7d 100644 --- a/lib/railties/lib/rails/templates/rails/components/index.html.erb +++ b/lib/railties/lib/rails/templates/rails/components/index.html.erb @@ -1,8 +1,8 @@ <% @previews.each do |preview| %> -

<%= link_to preview.preview_name.titleize, "/rails/components/#{preview.preview_name}" %>

+

<%= link_to preview.preview_name.titleize, "/rails/view_components/#{preview.preview_name}" %>

    <% preview.examples.each do |preview_example| %> -
  • <%= link_to preview_example, "/rails/components/#{preview.preview_name}/#{preview_example}" %>
  • +
  • <%= link_to preview_example, "/rails/view_components/#{preview.preview_name}/#{preview_example}" %>
  • <% end %>
<% end %> diff --git a/lib/railties/lib/rails/templates/rails/components/previews.html.erb b/lib/railties/lib/rails/templates/rails/components/previews.html.erb index fab22293c..6cfdde0b2 100644 --- a/lib/railties/lib/rails/templates/rails/components/previews.html.erb +++ b/lib/railties/lib/rails/templates/rails/components/previews.html.erb @@ -1,6 +1,6 @@

<%= @preview.preview_name.titleize %>

    <% @preview.examples.each do |example| %> -
  • <%= link_to example, "/rails/components/#{@preview.preview_name}/#{example}" %>
  • +
  • <%= link_to example, "/rails/view_components/#{@preview.preview_name}/#{example}" %>
  • <% end %>
diff --git a/lib/view_component.rb b/lib/view_component.rb index 667d2698f..03cdd31cb 100644 --- a/lib/view_component.rb +++ b/lib/view_component.rb @@ -6,7 +6,6 @@ module ViewComponent extend ActiveSupport::Autoload autoload :Base - autoload :Conversion autoload :Preview autoload :Previewable autoload :TestHelpers @@ -15,16 +14,3 @@ module ViewComponent autoload :RenderingMonkeyPatch autoload :TemplateError end - -module ActionView - module Component - extend ActiveSupport::Autoload - - autoload :Base - autoload :Preview - autoload :TestCase - autoload :TestHelpers - end -end - -ActiveModel::Conversion.include ViewComponent::Conversion diff --git a/lib/view_component/base.rb b/lib/view_component/base.rb index 0751791b6..bd8f23f1d 100644 --- a/lib/view_component/base.rb +++ b/lib/view_component/base.rb @@ -274,6 +274,6 @@ def compiled_template(file_path) end end - ActiveSupport.run_load_hooks(:action_view_component, self) + ActiveSupport.run_load_hooks(:view_component, self) end end diff --git a/lib/view_component/conversion.rb b/lib/view_component/conversion.rb deleted file mode 100644 index 59640462f..000000000 --- a/lib/view_component/conversion.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -module ViewComponent # :nodoc: - module Conversion - def to_component_class - "#{self.class.name}Component".safe_constantize - end - end -end diff --git a/lib/view_component/engine.rb b/lib/view_component/engine.rb index b4bad7608..e867f6c36 100644 --- a/lib/view_component/engine.rb +++ b/lib/view_component/engine.rb @@ -5,10 +5,10 @@ module ViewComponent class Engine < Rails::Engine # :nodoc: - config.action_view_component = ActiveSupport::OrderedOptions.new + config.view_component = ActiveSupport::OrderedOptions.new - initializer "action_view_component.set_configs" do |app| - options = app.config.action_view_component + initializer "view_component.set_configs" do |app| + options = app.config.view_component options.show_previews = Rails.env.development? if options.show_previews.nil? @@ -16,48 +16,48 @@ class Engine < Rails::Engine # :nodoc: options.preview_path ||= defined?(Rails.root) ? "#{Rails.root}/test/components/previews" : nil end - ActiveSupport.on_load(:action_view_component) do + ActiveSupport.on_load(:view_component) do options.each { |k, v| send("#{k}=", v) } end end - initializer "action_view_component.set_autoload_paths" do |app| - options = app.config.action_view_component + initializer "view_component.set_autoload_paths" do |app| + options = app.config.view_component if options.show_previews && options.preview_path ActiveSupport::Dependencies.autoload_paths << options.preview_path end end - initializer "action_view_component.eager_load_actions" do + initializer "view_component.eager_load_actions" do ActiveSupport.on_load(:after_initialize) do ViewComponent::Base.descendants.each(&:compile) end end - initializer "action_view_component.compile_config_methods" do - ActiveSupport.on_load(:action_view_component) do + initializer "view_component.compile_config_methods" do + ActiveSupport.on_load(:view_component) do config.compile_methods! if config.respond_to?(:compile_methods!) end end - initializer "action_view_component.monkey_patch_render" do + initializer "view_component.monkey_patch_render" do ActiveSupport.on_load(:action_view) do - ActionView::Base.prepend ViewComponent::RenderMonkeyPatch + ActionView::Base.prepend ViewComponent::RenderMonkeyPatch if Rails.version.to_f < 6.1 end ActiveSupport.on_load(:action_controller) do - ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch + ActionController::Base.prepend ViewComponent::RenderingMonkeyPatch if Rails.version.to_f < 6.1 end end config.after_initialize do |app| - options = app.config.action_view_component + options = app.config.view_component if options.show_previews app.routes.prepend do - get "/rails/components" => "rails/components#index", :internal => true - get "/rails/components/*path" => "rails/components#previews", :internal => true + get "/rails/view_components" => "rails/view_components#index", :internal => true + get "/rails/view_components/*path" => "rails/view_components#previews", :internal => true end end end diff --git a/lib/view_component/previewable.rb b/lib/view_component/previewable.rb index c4d746000..021351c34 100644 --- a/lib/view_component/previewable.rb +++ b/lib/view_component/previewable.rb @@ -9,13 +9,13 @@ module Previewable included do # Set the location of component previews through app configuration: # - # config.action_view_component.preview_path = "#{Rails.root}/lib/component_previews" + # config.view_component.preview_path = "#{Rails.root}/lib/component_previews" # mattr_accessor :preview_path, instance_writer: false # Enable or disable component previews through app configuration: # - # config.action_view_component.show_previews = true + # config.view_component.show_previews = true # # Defaults to +true+ for development environment # diff --git a/lib/view_component/render_monkey_patch.rb b/lib/view_component/render_monkey_patch.rb index cb47a45c9..0d05ac394 100644 --- a/lib/view_component/render_monkey_patch.rb +++ b/lib/view_component/render_monkey_patch.rb @@ -3,26 +3,8 @@ module ViewComponent module RenderMonkeyPatch # :nodoc: def render(options = {}, args = {}, &block) - if options.respond_to?(:render_in) && Rails.version.to_f < 6.1 + if options.respond_to?(:render_in) options.render_in(self, &block) - elsif options.is_a?(Class) && options < ActionView::Component::Base - ActiveSupport::Deprecation.warn( - "`render MyComponent, foo: :bar` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead." - ) - - options.new(args).render_in(self, &block) - elsif options.is_a?(Hash) && options.has_key?(:component) && options[:component] < ActionView::Component::Base - ActiveSupport::Deprecation.warn( - "`render component: MyComponent, locals: { foo: :bar }` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead." - ) - - options[:component].new(options[:locals]).render_in(self, &block) - elsif options.respond_to?(:to_component_class) && !options.to_component_class.nil? && options.to_component_class < ActionView::Component::Base - ActiveSupport::Deprecation.warn( - "rendering objects that respond_to `to_component_class` has been deprecated and will be removed in v2.0.0. Use `render MyComponent.new(foo: :bar)` instead." - ) - - options.to_component_class.new(options).render_in(self, &block) else super end diff --git a/lib/view_component/rendering_monkey_patch.rb b/lib/view_component/rendering_monkey_patch.rb index eeb5163c3..7a8bafbd4 100644 --- a/lib/view_component/rendering_monkey_patch.rb +++ b/lib/view_component/rendering_monkey_patch.rb @@ -3,7 +3,7 @@ module ViewComponent module RenderingMonkeyPatch # :nodoc: def render(options = {}, args = {}) - if options.respond_to?(:render_in) && Rails.version.to_f < 6.1 + if options.respond_to?(:render_in) self.response_body = options.render_in(self.view_context) else super diff --git a/lib/view_component/version.rb b/lib/view_component/version.rb index 91472ff2e..631284d34 100644 --- a/lib/view_component/version.rb +++ b/lib/view_component/version.rb @@ -2,8 +2,8 @@ module ViewComponent module VERSION - MAJOR = 1 - MINOR = 17 + MAJOR = 2 + MINOR = 0 PATCH = 0 STRING = [MAJOR, MINOR, PATCH].join(".") diff --git a/test/app/components/action_view_component.html.erb b/test/app/components/action_view_component.html.erb deleted file mode 100644 index 352ce9db3..000000000 --- a/test/app/components/action_view_component.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= content %> diff --git a/test/app/components/action_view_component.rb b/test/app/components/action_view_component.rb deleted file mode 100644 index 740d0274f..000000000 --- a/test/app/components/action_view_component.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class ActionViewComponent < ActionView::Component::Base - validates :content, presence: true - - def initialize(*); end -end diff --git a/test/app/components/post_component.html.erb b/test/app/components/post_component.html.erb deleted file mode 100644 index 5cb65df70..000000000 --- a/test/app/components/post_component.html.erb +++ /dev/null @@ -1 +0,0 @@ -The <%= @post.title %> component! diff --git a/test/app/components/post_component.rb b/test/app/components/post_component.rb deleted file mode 100644 index 2d87e4b02..000000000 --- a/test/app/components/post_component.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class PostComponent < ActionView::Component::Base - def initialize(post) - @post = post - end -end diff --git a/test/app/components/validations_component.rb b/test/app/components/validations_component.rb index 75f3df5b2..f3788beca 100644 --- a/test/app/components/validations_component.rb +++ b/test/app/components/validations_component.rb @@ -1,7 +1,13 @@ # frozen_string_literal: true -class ValidationsComponent < ActionView::Component::Base +class ValidationsComponent < ViewComponent::Base + include ActiveModel::Validations + validates :content, presence: true def initialize(*); end + + def before_render_check + validate! + end end diff --git a/test/app/views/integration_examples/component.html.erb b/test/app/views/integration_examples/component.html.erb deleted file mode 100644 index 76a8709d3..000000000 --- a/test/app/views/integration_examples/component.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render component: ActionViewComponent do %>Foo<% end %> diff --git a/test/app/views/integration_examples/deprecated.html.erb b/test/app/views/integration_examples/deprecated.html.erb deleted file mode 100644 index 526a19fcf..000000000 --- a/test/app/views/integration_examples/deprecated.html.erb +++ /dev/null @@ -1 +0,0 @@ -<%= render ActionViewComponent, message: "bar" do %>Foo<% end %> diff --git a/test/config/application.rb b/test/config/application.rb index 683bac979..52b0d0a7a 100644 --- a/test/config/application.rb +++ b/test/config/application.rb @@ -5,7 +5,7 @@ require "active_model/railtie" require "action_controller/railtie" require "action_view/railtie" -require "action_view/component/railtie" +require "view_component/engine" require "sprockets/railtie" require "better_html" diff --git a/test/config/environments/test.rb b/test/config/environments/test.rb index 9ad3ca4d1..e14d982c8 100644 --- a/test/config/environments/test.rb +++ b/test/config/environments/test.rb @@ -19,9 +19,9 @@ # Disable request forgery protection in test environment config.action_controller.allow_forgery_protection = false - config.action_view_component.show_previews = true + config.view_component.show_previews = true - config.action_view_component.test_controller = "IntegrationExamplesController" + config.view_component.test_controller = "IntegrationExamplesController" # Tell Action Mailer not to deliver emails to the real world. # The :test delivery method accumulates sent emails in the diff --git a/test/config/routes.rb b/test/config/routes.rb index 077c3e043..c07cfc7d8 100644 --- a/test/config/routes.rb +++ b/test/config/routes.rb @@ -2,7 +2,6 @@ Dummy::Application.routes.draw do root to: "integration_examples#index" - get :component, to: "integration_examples#component" get :content_areas, to: "integration_examples#content_areas" get :partial, to: "integration_examples#partial" get :content, to: "integration_examples#content" diff --git a/test/invalid_components_test_helper.rb b/test/invalid_components_test_helper.rb deleted file mode 100644 index 63244c3e6..000000000 --- a/test/invalid_components_test_helper.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -require "bundler/setup" -require "pp" -require "pathname" -require "minitest/autorun" - -# Configure Rails Envinronment -ENV["RAILS_ENV"] = "test" - -require "rails/test_help" diff --git a/test/test/components/previews/action_view_component_preview.rb b/test/test/components/previews/action_view_component_preview.rb deleted file mode 100644 index bca8da34c..000000000 --- a/test/test/components/previews/action_view_component_preview.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class ActionViewComponentPreview < ActionView::Component::Preview - layout "admin" - - def default - render(ActionViewComponent) - end -end diff --git a/test/view_component/action_view_component_test.rb b/test/view_component/action_view_component_test.rb deleted file mode 100644 index c5478f144..000000000 --- a/test/view_component/action_view_component_test.rb +++ /dev/null @@ -1,46 +0,0 @@ - # frozen_string_literal: true - -# This test exists to make sure the old APIs still work while we transition to the new -# name for the gem. - -class ActionView::ComponentTest < ActionView::Component::TestCase - def test_checks_validations - exception = assert_raises ActiveModel::ValidationError do - render_inline(ActionViewComponent.new) - end - - assert_includes exception.message, "Content can't be blank" - end - - def test_render_inline - render_inline(ActionViewComponent.new) { "hello,world!" } - - assert_selector("span", text: "hello,world!") - end - - def test_render_inline_with_class_syntax - render_inline(ActionViewComponent) { "hello,world!" } - - assert_selector("span", text: "hello,world!") - end - - def test_render_inline_with_hash_syntax - render_inline(component: ActionViewComponent) { "hello,world!" } - - assert_selector("span", text: "hello,world!") - end - - def test_to_component_class - post = Post.new(title: "Awesome post") - - render_inline(post).to_html - - assert_selector("span", text: "The Awesome post component!") - end - - def test_render_inline_with_old_helper - render_component(ActionViewComponent.new) - - assert_selector("div", text: "hello,world!") - end -end diff --git a/test/view_component/integration_test.rb b/test/view_component/integration_test.rb index 9a4524f5c..c161cf1a3 100644 --- a/test/view_component/integration_test.rb +++ b/test/view_component/integration_test.rb @@ -35,13 +35,6 @@ class IntegrationTest < ActionDispatch::IntegrationTest assert_includes response.body, "Open" end - test "rendering component in a view with component: syntax" do - get "/component" - assert_response :success - - assert_select("span", "Foo") - end - test "rendering component with content_for" do get "/content_areas" assert_response :success @@ -122,43 +115,43 @@ class IntegrationTest < ActionDispatch::IntegrationTest end test "renders component preview" do - get "/rails/components/my_component/default" + get "/rails/view_components/my_component/default" assert_includes response.body, "
hello,world!
" end test "renders preview component default preview" do - get "/rails/components/preview_component/default" + get "/rails/view_components/preview_component/default" assert_includes response.body, "Click me!" end test "renders preview component with_cta preview" do - get "/rails/components/preview_component/without_cta" + get "/rails/view_components/preview_component/without_cta" assert_includes response.body, "More lorem..." end test "renders preview component with content preview" do - get "/rails/components/preview_component/with_content" + get "/rails/view_components/preview_component/with_content" assert_includes response.body, "some content" end test "renders preview component with tag helper-generated content preview" do - get "/rails/components/preview_component/with_tag_helper_in_content" + get "/rails/view_components/preview_component/with_tag_helper_in_content" assert_includes response.body, "some content" end test "renders badge component open preview" do - get "/rails/components/issues/badge_component/open" + get "/rails/view_components/issues/badge_component/open" assert_includes response.body, "Open" end test "renders badge component closed preview" do - get "/rails/components/issues/badge_component/closed" + get "/rails/view_components/issues/badge_component/closed" assert_includes response.body, "Closed" end diff --git a/test/view_component/invalid_components_test.rb b/test/view_component/invalid_components_test.rb index 651ff55cb..1104b2d66 100644 --- a/test/view_component/invalid_components_test.rb +++ b/test/view_component/invalid_components_test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -class ActionView::InvalidComponentTest < ViewComponent::TestCase +class InvalidComponentTest < ViewComponent::TestCase def test_raises_error_when_initializer_is_not_defined exception = assert_raises ViewComponent::TemplateError do render_inline(MissingInitializerComponent.new) diff --git a/test/view_component/preview_test.rb b/test/view_component/preview_test.rb index a3c1fd213..1f9e06ab2 100644 --- a/test/view_component/preview_test.rb +++ b/test/view_component/preview_test.rb @@ -4,7 +4,7 @@ class ViewComponent::PreviewTest < ActionDispatch::IntegrationTest def test_preview - get "/rails/components/preview_component/default" + get "/rails/view_components/preview_component/default" assert_html_document( response.body, @@ -21,7 +21,7 @@ def test_preview end def test_preview_with_layout - get "/rails/components/my_component/default" + get "/rails/view_components/my_component/default" assert_html_document( response.body, @@ -31,7 +31,7 @@ def test_preview_with_layout end def test_preview_with_no_layout - get "/rails/components/no_layout/default" + get "/rails/view_components/no_layout/default" assert_html_fragment( response.body,