Module: LcpRuby::Kanban::ProviderTestHarness
- Defined in:
- lib/lcp_ruby/kanban/provider_test_harness.rb
Overview
Test helpers for host-app provider unit tests. Include in RSpec specs:
RSpec.describe MyProvider do
include LcpRuby::Kanban::ProviderTestHarness
...
end
Provides factories for the kwargs every HostProvider receives. Host apps still supply real AR relations for ‘scope` (so queries run against a test DB), but the harness centralizes the boilerplate around `context`, `user`, and column assertions.
Instance Method Summary collapse
-
#assert_kanban_column_values(columns_or_board, expected_values) ⇒ Object
Asserts the column values of a Board (or array of Columns), in order.
-
#build_kanban_context(params: {}, locale: nil, saved_filter: nil, view_group: nil, presenter_slug: nil, kanban_column: nil, kanban_page: nil) ⇒ Object
Builds a Hash that mimics the request ‘context` LCP passes to providers.
-
#build_kanban_test_user(id: 1, roles: []) ⇒ Object
Returns a stub user object — sufficient when the provider does not consult ‘user.roles` / `user.id`.
Instance Method Details
#assert_kanban_column_values(columns_or_board, expected_values) ⇒ Object
Asserts the column values of a Board (or array of Columns), in order. Use in RSpec specs alongside ‘expect(…)` for full integration; this helper exists so host apps without RSpec can still assert.
44 45 46 47 48 49 50 51 |
# File 'lib/lcp_ruby/kanban/provider_test_harness.rb', line 44 def assert_kanban_column_values(columns_or_board, expected_values) cols = columns_or_board.respond_to?(:columns) ? columns_or_board.columns : columns_or_board actual = cols.map { |c| c.value.to_s } expected = expected_values.map(&:to_s) return if actual == expected raise "Expected kanban columns #{expected.inspect}, got #{actual.inspect}" end |
#build_kanban_context(params: {}, locale: nil, saved_filter: nil, view_group: nil, presenter_slug: nil, kanban_column: nil, kanban_page: nil) ⇒ Object
Builds a Hash that mimics the request ‘context` LCP passes to providers. Default keys cover Phase 1; new keys can be added in later phases without breaking existing harness callers (additive contract).
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lcp_ruby/kanban/provider_test_harness.rb', line 20 def build_kanban_context(params: {}, locale: nil, saved_filter: nil, view_group: nil, presenter_slug: nil, kanban_column: nil, kanban_page: nil) { params: params, locale: locale || I18n.default_locale, saved_filter: saved_filter, view_group: view_group, presenter_slug: presenter_slug, kanban_column: kanban_column, kanban_page: kanban_page } end |
#build_kanban_test_user(id: 1, roles: []) ⇒ Object
Returns a stub user object — sufficient when the provider does not consult ‘user.roles` / `user.id`. Replace with a real test user when authorization matters.
37 38 39 |
# File 'lib/lcp_ruby/kanban/provider_test_harness.rb', line 37 def build_kanban_test_user(id: 1, roles: []) OpenStruct.new(id: id, roles: Array(roles)) end |