Skip to content

Commit

Permalink
Merge pull request #230 from fcheung/fix-view-context-access-from-com…
Browse files Browse the repository at this point in the history
…ponent-test

Fix not being able to use view context from component tests
  • Loading branch information
joeldrapper authored Oct 1, 2024
2 parents 5f57e0c + 19c5f41 commit 7dee942
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ gem "yard"
gem "rails"
gem "puma"
gem "sqlite3"

gem "capybara"
2 changes: 1 addition & 1 deletion lib/phlex/rails/testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ def controller
end
end

Phlex::Testing::SGML.include(
Phlex::Testing::SGML.prepend(
Phlex::Testing::RailsContext,
)
21 changes: 21 additions & 0 deletions test/phlex/test_helpers_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require "test_helper"

class TestHelpersTest < ActiveSupport::TestCase
include Phlex::Testing::Capybara

class PartialFromPhlex < ApplicationView
def view_template
render partial: "rendering/partial" do
h1(id: "phlex") { "Partial from Phlex" }
end
end
end

test "renders a card" do
render PartialFromPhlex.new

assert_selector "#erb>h1#phlex", text: "Partial from Phlex"
end
end
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
require_relative "../test/dummy/config/environment"
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
require "rails/test_help"

require "phlex/rails/testing"
# Load fixtures from the engine
if ActiveSupport::TestCase.respond_to?(:fixture_paths=)
ActiveSupport::TestCase.fixture_paths = [File.expand_path("fixtures", __dir__)]
Expand Down

0 comments on commit 7dee942

Please sign in to comment.