uchi 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +222 -0
- data/app/assets/config/uchi_manifest.js +2 -0
- data/app/assets/javascripts/uchi/application.js +6095 -0
- data/app/assets/javascripts/uchi.js +4 -0
- data/app/assets/stylesheets/uchi/application.css +3971 -0
- data/app/assets/stylesheets/uchi/uchi.css +17 -0
- data/app/assets/tailwind/uchi.css +21 -0
- data/app/components/flowbite/breadcrumb.rb +33 -0
- data/app/components/flowbite/breadcrumb_home.rb +26 -0
- data/app/components/flowbite/breadcrumb_item/current.rb +33 -0
- data/app/components/flowbite/breadcrumb_item/first.rb +35 -0
- data/app/components/flowbite/breadcrumb_item.rb +48 -0
- data/app/components/flowbite/breadcrumb_separator.rb +30 -0
- data/app/components/flowbite/button/outline.rb +22 -0
- data/app/components/flowbite/button/pill.rb +40 -0
- data/app/components/flowbite/button.rb +92 -0
- data/app/components/flowbite/card.rb +45 -0
- data/app/components/flowbite/input/checkbox.rb +73 -0
- data/app/components/flowbite/input/date.rb +11 -0
- data/app/components/flowbite/input/date_time.rb +11 -0
- data/app/components/flowbite/input/email.rb +12 -0
- data/app/components/flowbite/input/field.rb +117 -0
- data/app/components/flowbite/input/file.rb +30 -0
- data/app/components/flowbite/input/hint.rb +57 -0
- data/app/components/flowbite/input/label.rb +82 -0
- data/app/components/flowbite/input/number.rb +11 -0
- data/app/components/flowbite/input/password.rb +11 -0
- data/app/components/flowbite/input/phone.rb +11 -0
- data/app/components/flowbite/input/radio_button.rb +50 -0
- data/app/components/flowbite/input/select.rb +49 -0
- data/app/components/flowbite/input/textarea.rb +42 -0
- data/app/components/flowbite/input/url.rb +12 -0
- data/app/components/flowbite/input/validation_error.rb +11 -0
- data/app/components/flowbite/input_field/checkbox.html.erb +14 -0
- data/app/components/flowbite/input_field/checkbox.rb +54 -0
- data/app/components/flowbite/input_field/date.rb +13 -0
- data/app/components/flowbite/input_field/date_time.rb +13 -0
- data/app/components/flowbite/input_field/email.rb +13 -0
- data/app/components/flowbite/input_field/file.rb +13 -0
- data/app/components/flowbite/input_field/input_field.html.erb +8 -0
- data/app/components/flowbite/input_field/number.rb +13 -0
- data/app/components/flowbite/input_field/password.rb +13 -0
- data/app/components/flowbite/input_field/phone.rb +13 -0
- data/app/components/flowbite/input_field/radio_button.html.erb +14 -0
- data/app/components/flowbite/input_field/radio_button.rb +86 -0
- data/app/components/flowbite/input_field/select.rb +31 -0
- data/app/components/flowbite/input_field/text.rb +8 -0
- data/app/components/flowbite/input_field/textarea.rb +13 -0
- data/app/components/flowbite/input_field/url.rb +13 -0
- data/app/components/flowbite/input_field.rb +192 -0
- data/app/components/flowbite/link.rb +21 -0
- data/app/components/flowbite/style.rb +13 -0
- data/app/components/flowbite/toast/icon.html.erb +5 -0
- data/app/components/flowbite/toast/icon.rb +57 -0
- data/app/components/flowbite/toast/toast.html.erb +11 -0
- data/app/components/flowbite/toast.rb +34 -0
- data/app/components/uchi/field/base.rb +57 -0
- data/app/components/uchi/field/belongs_to/edit.html.erb +1 -0
- data/app/components/uchi/field/belongs_to/index.html.erb +1 -0
- data/app/components/uchi/field/belongs_to/show.html.erb +3 -0
- data/app/components/uchi/field/belongs_to.rb +105 -0
- data/app/components/uchi/field/blank/edit.html.erb +1 -0
- data/app/components/uchi/field/blank/index.html.erb +1 -0
- data/app/components/uchi/field/blank/show.html.erb +1 -0
- data/app/components/uchi/field/blank.rb +16 -0
- data/app/components/uchi/field/boolean/edit.html.erb +1 -0
- data/app/components/uchi/field/boolean/index.html.erb +9 -0
- data/app/components/uchi/field/boolean/show.html.erb +9 -0
- data/app/components/uchi/field/boolean.rb +27 -0
- data/app/components/uchi/field/date/edit.html.erb +1 -0
- data/app/components/uchi/field/date/index.html.erb +1 -0
- data/app/components/uchi/field/date/show.html.erb +1 -0
- data/app/components/uchi/field/date.rb +27 -0
- data/app/components/uchi/field/date_time/edit.html.erb +1 -0
- data/app/components/uchi/field/date_time/index.html.erb +1 -0
- data/app/components/uchi/field/date_time/show.html.erb +1 -0
- data/app/components/uchi/field/date_time.rb +27 -0
- data/app/components/uchi/field/file/edit.html.erb +1 -0
- data/app/components/uchi/field/file/index.html.erb +6 -0
- data/app/components/uchi/field/file/show.html.erb +8 -0
- data/app/components/uchi/field/file.rb +37 -0
- data/app/components/uchi/field/has_and_belongs_to_many/edit.html.erb +9 -0
- data/app/components/uchi/field/has_and_belongs_to_many/index.html.erb +1 -0
- data/app/components/uchi/field/has_and_belongs_to_many/show.html.erb +28 -0
- data/app/components/uchi/field/has_and_belongs_to_many.rb +131 -0
- data/app/components/uchi/field/has_many/edit.html.erb +1 -0
- data/app/components/uchi/field/has_many/index.html.erb +1 -0
- data/app/components/uchi/field/has_many/show.html.erb +28 -0
- data/app/components/uchi/field/has_many.rb +107 -0
- data/app/components/uchi/field/id/index.html.erb +4 -0
- data/app/components/uchi/field/id/show.html.erb +4 -0
- data/app/components/uchi/field/id.rb +26 -0
- data/app/components/uchi/field/image/edit.html.erb +1 -0
- data/app/components/uchi/field/image/index.html.erb +6 -0
- data/app/components/uchi/field/image/show.html.erb +6 -0
- data/app/components/uchi/field/image.rb +38 -0
- data/app/components/uchi/field/number/edit.html.erb +1 -0
- data/app/components/uchi/field/number/index.html.erb +1 -0
- data/app/components/uchi/field/number/show.html.erb +1 -0
- data/app/components/uchi/field/number.rb +32 -0
- data/app/components/uchi/field/string/edit.html.erb +1 -0
- data/app/components/uchi/field/string/index.html.erb +1 -0
- data/app/components/uchi/field/string/show.html.erb +1 -0
- data/app/components/uchi/field/string.rb +33 -0
- data/app/components/uchi/field/text/edit.html.erb +1 -0
- data/app/components/uchi/field/text/index.html.erb +1 -0
- data/app/components/uchi/field/text/show.html.erb +1 -0
- data/app/components/uchi/field/text.rb +38 -0
- data/app/components/uchi/ui/breadcrumb/breadcrumb.html.erb +13 -0
- data/app/components/uchi/ui/breadcrumb.rb +14 -0
- data/app/components/uchi/ui/form/footer/footer.html.erb +5 -0
- data/app/components/uchi/ui/form/footer.rb +15 -0
- data/app/components/uchi/ui/form/input/collection_checkboxes.html.erb +32 -0
- data/app/components/uchi/ui/form/input/collection_checkboxes.rb +125 -0
- data/app/components/uchi/ui/frame/frame.html.erb +3 -0
- data/app/components/uchi/ui/frame.rb +10 -0
- data/app/components/uchi/ui/index/records_table/records_table.html.erb +67 -0
- data/app/components/uchi/ui/index/records_table/search_form/search_form.html.erb +21 -0
- data/app/components/uchi/ui/index/records_table/search_form.rb +49 -0
- data/app/components/uchi/ui/index/records_table.rb +29 -0
- data/app/components/uchi/ui/index/turbo_frame.rb +50 -0
- data/app/components/uchi/ui/page_header/page_header.html.erb +24 -0
- data/app/components/uchi/ui/page_header.rb +18 -0
- data/app/components/uchi/ui/pagination/current_link.html.erb +3 -0
- data/app/components/uchi/ui/pagination/current_link.rb +10 -0
- data/app/components/uchi/ui/pagination/gap.html.erb +3 -0
- data/app/components/uchi/ui/pagination/gap.rb +10 -0
- data/app/components/uchi/ui/pagination/item.rb +24 -0
- data/app/components/uchi/ui/pagination/link.html.erb +3 -0
- data/app/components/uchi/ui/pagination/link.rb +10 -0
- data/app/components/uchi/ui/pagination/next_link.html.erb +8 -0
- data/app/components/uchi/ui/pagination/next_link.rb +22 -0
- data/app/components/uchi/ui/pagination/pagination.html.erb +15 -0
- data/app/components/uchi/ui/pagination/previous_link.html.erb +8 -0
- data/app/components/uchi/ui/pagination/previous_link.rb +22 -0
- data/app/components/uchi/ui/pagination.rb +48 -0
- data/app/components/uchi/ui/show/attribute_fields/attribute_fields.html.erb +14 -0
- data/app/components/uchi/ui/show/attribute_fields.rb +18 -0
- data/app/components/uchi/ui/spinner/spinner.html.erb +7 -0
- data/app/components/uchi/ui/spinner.rb +15 -0
- data/app/controllers/uchi/application_controller.rb +4 -0
- data/app/controllers/uchi/controller.rb +13 -0
- data/app/controllers/uchi/repository_controller.rb +166 -0
- data/app/helpers/uchi/application_helper.rb +17 -0
- data/app/jobs/uchi/application_job.rb +4 -0
- data/app/mailers/uchi/application_mailer.rb +6 -0
- data/app/views/layouts/uchi/_flash_messages.html.erb +10 -0
- data/app/views/layouts/uchi/application.html.erb +33 -0
- data/app/views/uchi/repository/edit.html.erb +40 -0
- data/app/views/uchi/repository/index.html.erb +49 -0
- data/app/views/uchi/repository/new.html.erb +37 -0
- data/app/views/uchi/repository/show.html.erb +41 -0
- data/lib/generators/uchi/controller/controller_generator.rb +16 -0
- data/lib/generators/uchi/controller/templates/controller.rb.tt +11 -0
- data/lib/generators/uchi/install/install_generator.rb +13 -0
- data/lib/generators/uchi/repository/repository_generator.rb +16 -0
- data/lib/generators/uchi/repository/templates/repository.rb.tt +11 -0
- data/lib/tasks/uchi_tasks.rake +4 -0
- data/lib/uchi/application_record.rb +5 -0
- data/lib/uchi/engine.rb +24 -0
- data/lib/uchi/field/configuration.rb +142 -0
- data/lib/uchi/field.rb +80 -0
- data/lib/uchi/i18n.rb +13 -0
- data/lib/uchi/pagination/controller.rb +26 -0
- data/lib/uchi/pagination/page.rb +20 -0
- data/lib/uchi/pagy/LICENSE.txt +21 -0
- data/lib/uchi/pagy/classes/exceptions.rb +35 -0
- data/lib/uchi/pagy/classes/offset/offset.rb +56 -0
- data/lib/uchi/pagy/classes/request.rb +38 -0
- data/lib/uchi/pagy/modules/abilities/configurable.rb +38 -0
- data/lib/uchi/pagy/modules/abilities/linkable.rb +62 -0
- data/lib/uchi/pagy/modules/abilities/rangeable.rb +17 -0
- data/lib/uchi/pagy/modules/abilities/shiftable.rb +14 -0
- data/lib/uchi/pagy/modules/console.rb +40 -0
- data/lib/uchi/pagy/toolbox/helpers/loader.rb +19 -0
- data/lib/uchi/pagy/toolbox/helpers/page_url.rb +25 -0
- data/lib/uchi/pagy/toolbox/paginators/method.rb +21 -0
- data/lib/uchi/pagy/toolbox/paginators/offset.rb +35 -0
- data/lib/uchi/pagy.rb +60 -0
- data/lib/uchi/repository/routes.rb +62 -0
- data/lib/uchi/repository/translate.rb +284 -0
- data/lib/uchi/repository.rb +156 -0
- data/lib/uchi/sort_order.rb +35 -0
- data/lib/uchi/version.rb +5 -0
- data/lib/uchi.rb +18 -0
- data/uchi.gemspec +35 -0
- metadata +197 -107
- data/.github/dependabot.yml +0 -17
- data/.github/workflows/build.yml +0 -23
- data/.github/workflows/lint.yml +0 -30
- data/package.json +0 -31
- data/sig/uchi.rbs +0 -4
- data/test/components/uchi/field/belongs_to_test.rb +0 -134
- data/test/components/uchi/field/blank_test.rb +0 -119
- data/test/components/uchi/field/boolean_test.rb +0 -163
- data/test/components/uchi/field/date_test.rb +0 -163
- data/test/components/uchi/field/date_time_test.rb +0 -152
- data/test/components/uchi/field/has_many_test.rb +0 -138
- data/test/components/uchi/field/id_test.rb +0 -113
- data/test/components/uchi/field/number_test.rb +0 -163
- data/test/components/uchi/field/string_test.rb +0 -159
- data/test/controllers/uchi/authors_controller_test.rb +0 -119
- data/test/controllers/uchi/repository_controller_test.rb +0 -93
- data/test/controllers/uchi/scoped_repository_controller_test.rb +0 -73
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/stylesheets/application.css +0 -15
- data/test/dummy/app/controllers/application_controller.rb +0 -4
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/controllers/uchi/authors_controller.rb +0 -7
- data/test/dummy/app/controllers/uchi/books_controller.rb +0 -7
- data/test/dummy/app/controllers/uchi/titles_controller.rb +0 -7
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/jobs/application_job.rb +0 -7
- data/test/dummy/app/mailers/application_mailer.rb +0 -4
- data/test/dummy/app/models/application_record.rb +0 -3
- data/test/dummy/app/models/author.rb +0 -3
- data/test/dummy/app/models/book.rb +0 -3
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/models/title.rb +0 -3
- data/test/dummy/app/uchi/repositories/author.rb +0 -20
- data/test/dummy/app/uchi/repositories/book.rb +0 -16
- data/test/dummy/app/uchi/repositories/title.rb +0 -17
- data/test/dummy/app/views/layouts/application.html.erb +0 -27
- data/test/dummy/app/views/layouts/mailer.html.erb +0 -13
- data/test/dummy/app/views/layouts/mailer.text.erb +0 -1
- data/test/dummy/app/views/pwa/manifest.json.erb +0 -22
- data/test/dummy/app/views/pwa/service-worker.js +0 -26
- data/test/dummy/bin/dev +0 -2
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/bin/setup +0 -34
- data/test/dummy/config/application.rb +0 -29
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/cable.yml +0 -10
- data/test/dummy/config/database.yml +0 -32
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -69
- data/test/dummy/config/environments/production.rb +0 -89
- data/test/dummy/config/environments/test.rb +0 -53
- data/test/dummy/config/initializers/content_security_policy.rb +0 -25
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -8
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/locales/da.yml +0 -51
- data/test/dummy/config/locales/en.yml +0 -31
- data/test/dummy/config/puma.rb +0 -38
- data/test/dummy/config/routes.rb +0 -9
- data/test/dummy/config/storage.yml +0 -34
- data/test/dummy/config.ru +0 -6
- data/test/dummy/db/migrate/20251002183635_create_authors.rb +0 -11
- data/test/dummy/db/migrate/20251005131726_create_books.rb +0 -9
- data/test/dummy/db/migrate/20251005131811_create_titles.rb +0 -11
- data/test/dummy/db/schema.rb +0 -38
- data/test/dummy/log/.keep +0 -0
- data/test/dummy/public/400.html +0 -114
- data/test/dummy/public/404.html +0 -114
- data/test/dummy/public/406-unsupported-browser.html +0 -114
- data/test/dummy/public/422.html +0 -114
- data/test/dummy/public/500.html +0 -114
- data/test/dummy/public/icon.png +0 -0
- data/test/dummy/public/icon.svg +0 -3
- data/test/dummy/storage/.keep +0 -0
- data/test/dummy/test/fixtures/authors.yml +0 -11
- data/test/dummy/test/models/author_test.rb +0 -7
- data/test/dummy/tmp/.keep +0 -0
- data/test/dummy/tmp/pids/.keep +0 -0
- data/test/dummy/tmp/storage/.keep +0 -0
- data/test/test_helper.rb +0 -15
- data/test/uchi/field_test.rb +0 -63
- data/test/uchi/i18n_test.rb +0 -18
- data/test/uchi/repository/routes_test.rb +0 -49
- data/test/uchi/repository/translate_test.rb +0 -263
- data/test/uchi/repository_test.rb +0 -137
- data/test/uchi/sort_order_test.rb +0 -47
- data/test/uchi_test.rb +0 -7
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
require "ostruct"
|
|
3
|
-
|
|
4
|
-
module Uchi
|
|
5
|
-
class Field
|
|
6
|
-
class HasManyTest < ActiveSupport::TestCase
|
|
7
|
-
def setup
|
|
8
|
-
@field = Uchi::Field::HasMany.new(:titles)
|
|
9
|
-
@form = OpenStruct.new(object: Book.new)
|
|
10
|
-
@repository = Uchi::Repositories::Book.new
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test "inherits from Uchi::Field" do
|
|
14
|
-
assert_kind_of Uchi::Field, @field
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
test "has default options specific to HasMany field" do
|
|
18
|
-
assert_equal [:show], @field.on # Different from other fields - only on show
|
|
19
|
-
assert_not @field.searchable?
|
|
20
|
-
assert @field.sortable?
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test "has custom collection_query" do
|
|
24
|
-
custom_query = ->(query) { query.where(published: true) }
|
|
25
|
-
field = Uchi::Field::HasMany.new(:titles, collection_query: custom_query)
|
|
26
|
-
assert_equal custom_query, field.collection_query
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
test "uses default collection_query" do
|
|
30
|
-
assert_equal Uchi::Field::HasMany::DEFAULT_COLLECTION_QUERY, @field.collection_query
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
test "#param_key returns foreign key name" do
|
|
34
|
-
assert_equal :titles_id, @field.param_key
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
test "#group_as returns :associations" do
|
|
38
|
-
assert_equal :associations, @field.group_as(:show)
|
|
39
|
-
assert_equal :associations, @field.group_as(:edit)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
test "#edit_component returns an instance of Edit component" do
|
|
43
|
-
component = @field.edit_component(form: @form, hint: "Custom hint", label: "Custom label", repository: @repository)
|
|
44
|
-
assert_equal "Custom hint", component.hint
|
|
45
|
-
assert_equal "Custom label", component.label
|
|
46
|
-
assert_equal @field, component.field
|
|
47
|
-
assert_equal @form, component.form
|
|
48
|
-
assert_equal @repository, component.repository
|
|
49
|
-
assert_kind_of Uchi::Field::HasMany::Edit, component
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
test "#index_component returns an instance of Index component" do
|
|
53
|
-
component = @field.index_component(record: @form.object, repository: @repository)
|
|
54
|
-
assert_equal @field, component.field
|
|
55
|
-
assert_equal @form.object, component.record
|
|
56
|
-
assert_equal @repository, component.repository
|
|
57
|
-
assert_kind_of Uchi::Field::HasMany::Index, component
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test "#show_component returns an instance of Show component" do
|
|
61
|
-
component = @field.show_component(record: @form.object, repository: @repository)
|
|
62
|
-
assert_equal @field, component.field
|
|
63
|
-
assert_equal @form.object, component.record
|
|
64
|
-
assert_equal @repository, component.repository
|
|
65
|
-
assert_kind_of Uchi::Field::HasMany::Show, component
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
test "#searchable? returns false when explicitly set" do
|
|
69
|
-
field = Uchi::Field::HasMany.new(:titles, searchable: false)
|
|
70
|
-
assert_not field.searchable?
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
test "#sortable? returns false when explicitly set" do
|
|
74
|
-
field = Uchi::Field::HasMany.new(:titles, sortable: false)
|
|
75
|
-
assert_not field.sortable?
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
class HasManyEditTest < ViewComponent::TestCase
|
|
80
|
-
def setup
|
|
81
|
-
@field = Uchi::Field::HasMany.new(:titles)
|
|
82
|
-
@book = Book.new(original_title: "The Hobbit")
|
|
83
|
-
@repository = Uchi::Repositories::Book.new
|
|
84
|
-
@view_context = ActionController::Base.new.view_context
|
|
85
|
-
|
|
86
|
-
@form = ActionView::Helpers::FormBuilder.new(:book, @book, @view_context, {})
|
|
87
|
-
|
|
88
|
-
@component = Uchi::Field::HasMany::Edit.new(
|
|
89
|
-
field: @field,
|
|
90
|
-
form: @form,
|
|
91
|
-
hint: "Custom hint",
|
|
92
|
-
label: "Custom label",
|
|
93
|
-
repository: @repository
|
|
94
|
-
)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
test "inherits from Base component" do
|
|
98
|
-
assert_kind_of Uchi::Field::Base::Edit, @component
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
class HasManyIndexTest < ViewComponent::TestCase
|
|
103
|
-
def setup
|
|
104
|
-
@field = Uchi::Field::HasMany.new(:titles)
|
|
105
|
-
@book = Book.new(original_title: "The Hobbit")
|
|
106
|
-
@repository = Uchi::Repositories::Book.new
|
|
107
|
-
|
|
108
|
-
@component = Uchi::Field::HasMany::Index.new(
|
|
109
|
-
field: @field,
|
|
110
|
-
record: @book,
|
|
111
|
-
repository: @repository
|
|
112
|
-
)
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
test "inherits from Base component" do
|
|
116
|
-
assert_kind_of Uchi::Field::Base::Index, @component
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
class HasManyShowTest < ViewComponent::TestCase
|
|
121
|
-
def setup
|
|
122
|
-
@field = Uchi::Field::HasMany.new(:titles)
|
|
123
|
-
@book = Book.new(original_title: "The Hobbit")
|
|
124
|
-
@repository = Uchi::Repositories::Book.new
|
|
125
|
-
|
|
126
|
-
@component = Uchi::Field::HasMany::Show.new(
|
|
127
|
-
field: @field,
|
|
128
|
-
record: @book,
|
|
129
|
-
repository: @repository
|
|
130
|
-
)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
test "inherits from Base component" do
|
|
134
|
-
assert_kind_of Uchi::Field::Base::Show, @component
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
end
|
|
138
|
-
end
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
require "ostruct"
|
|
3
|
-
|
|
4
|
-
module Uchi
|
|
5
|
-
class Field
|
|
6
|
-
class IdTest < ActiveSupport::TestCase
|
|
7
|
-
def setup
|
|
8
|
-
@field = Uchi::Field::Id.new(:id)
|
|
9
|
-
@form = OpenStruct.new(object: OpenStruct.new(id: 123))
|
|
10
|
-
@repository = Uchi::Repositories::Author.new
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test "inherits from Uchi::Field::Number" do
|
|
14
|
-
assert_kind_of Uchi::Field::Number, @field
|
|
15
|
-
assert_kind_of Uchi::Field, @field
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
test "has default options specific to Id field" do
|
|
19
|
-
assert_equal [:index, :show], @field.on # Different from other fields
|
|
20
|
-
assert @field.searchable? # Different from other fields
|
|
21
|
-
assert @field.sortable?
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
test "does not have edit_component because not in :edit on list" do
|
|
25
|
-
# Since Id field defaults to [:index, :show], it doesn't include :edit
|
|
26
|
-
# But we can still create the component if needed
|
|
27
|
-
assert_nothing_raised do
|
|
28
|
-
@field.edit_component(form: @form, hint: "Custom hint", label: "Custom label", repository: @repository)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
test "#index_component returns an instance of Index component" do
|
|
33
|
-
component = @field.index_component(record: @form.object, repository: @repository)
|
|
34
|
-
assert_equal @field, component.field
|
|
35
|
-
assert_equal @form.object, component.record
|
|
36
|
-
assert_equal @repository, component.repository
|
|
37
|
-
assert_kind_of Uchi::Field::Id::Index, component
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
test "#searchable? returns true by default for Id field" do
|
|
41
|
-
assert @field.searchable?
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
test "#searchable? returns false when explicitly set" do
|
|
45
|
-
field = Uchi::Field::Id.new(:id, searchable: false)
|
|
46
|
-
assert_not field.searchable?
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
test "#show_component returns an instance of Show component" do
|
|
50
|
-
component = @field.show_component(record: @form.object, repository: @repository)
|
|
51
|
-
assert_equal @field, component.field
|
|
52
|
-
assert_equal @form.object, component.record
|
|
53
|
-
assert_equal @repository, component.repository
|
|
54
|
-
assert_kind_of Uchi::Field::Id::Show, component
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
test "#sortable? returns false when explicitly set" do
|
|
58
|
-
field = Uchi::Field::Id.new(:id, sortable: false)
|
|
59
|
-
assert_not field.sortable?
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
class IdIndexTest < ViewComponent::TestCase
|
|
64
|
-
def setup
|
|
65
|
-
@field = Uchi::Field::Id.new(:id)
|
|
66
|
-
@record = Author.new(name: "Test Author")
|
|
67
|
-
@record.define_singleton_method(:id) { 123 }
|
|
68
|
-
@repository = Uchi::Repositories::Author.new
|
|
69
|
-
|
|
70
|
-
@component = Uchi::Field::Id::Index.new(
|
|
71
|
-
field: @field,
|
|
72
|
-
record: @record,
|
|
73
|
-
repository: @repository
|
|
74
|
-
)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
test "inherits from Base component" do
|
|
78
|
-
assert_kind_of Uchi::Field::Base::Index, @component
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
test "renders the field content" do
|
|
82
|
-
result = render_inline(@component)
|
|
83
|
-
|
|
84
|
-
assert_includes result.to_html, "123"
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
class IdShowTest < ViewComponent::TestCase
|
|
89
|
-
def setup
|
|
90
|
-
@field = Uchi::Field::Id.new(:id)
|
|
91
|
-
@record = Author.new(name: "Test Author")
|
|
92
|
-
@record.define_singleton_method(:id) { 123 }
|
|
93
|
-
@repository = Uchi::Repositories::Author.new
|
|
94
|
-
|
|
95
|
-
@component = Uchi::Field::Id::Show.new(
|
|
96
|
-
field: @field,
|
|
97
|
-
record: @record,
|
|
98
|
-
repository: @repository
|
|
99
|
-
)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
test "inherits from Base component" do
|
|
103
|
-
assert_kind_of Uchi::Field::Base::Show, @component
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
test "renders the field content" do
|
|
107
|
-
result = render_inline(@component)
|
|
108
|
-
|
|
109
|
-
assert_includes result.to_html, "123"
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
require "ostruct"
|
|
3
|
-
|
|
4
|
-
module Uchi
|
|
5
|
-
class Field
|
|
6
|
-
class NumberTest < ActiveSupport::TestCase
|
|
7
|
-
def setup
|
|
8
|
-
@field = Uchi::Field::Number.new(:age)
|
|
9
|
-
@form = OpenStruct.new(object: OpenStruct.new(age: 25))
|
|
10
|
-
@repository = Uchi::Repositories::Author.new
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test "inherits from Uchi::Field" do
|
|
14
|
-
assert_kind_of Uchi::Field, @field
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
test "has default options" do
|
|
18
|
-
assert_equal [:edit, :index, :show], @field.on
|
|
19
|
-
assert_not @field.searchable?
|
|
20
|
-
assert @field.sortable?
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test "#edit_component returns an instance of Edit component" do
|
|
24
|
-
component = @field.edit_component(form: @form, hint: "Custom hint", label: "Custom label", repository: @repository)
|
|
25
|
-
assert_equal "Custom hint", component.hint
|
|
26
|
-
assert_equal "Custom label", component.label
|
|
27
|
-
assert_equal @field, component.field
|
|
28
|
-
assert_equal @form, component.form
|
|
29
|
-
assert_equal @repository, component.repository
|
|
30
|
-
assert_kind_of Uchi::Field::Number::Edit, component
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
test "#index_component returns an instance of Index component" do
|
|
34
|
-
component = @field.index_component(record: @form.object, repository: @repository)
|
|
35
|
-
assert_equal @field, component.field
|
|
36
|
-
assert_equal @form.object, component.record
|
|
37
|
-
assert_equal @repository, component.repository
|
|
38
|
-
assert_kind_of Uchi::Field::Number::Index, component
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
test "#searchable? returns false when explicitly set" do
|
|
42
|
-
field = Uchi::Field::Number.new(:age, searchable: false)
|
|
43
|
-
assert_not field.searchable?
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
test "#show_component returns an instance of Show component" do
|
|
47
|
-
component = @field.show_component(record: @form.object, repository: @repository)
|
|
48
|
-
assert_equal @field, component.field
|
|
49
|
-
assert_equal @form.object, component.record
|
|
50
|
-
assert_equal @repository, component.repository
|
|
51
|
-
assert_kind_of Uchi::Field::Number::Show, component
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
test "#sortable? returns false when explicitly set" do
|
|
55
|
-
field = Uchi::Field::Number.new(:age, sortable: false)
|
|
56
|
-
assert_not field.sortable?
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
class NumberEditTest < ViewComponent::TestCase
|
|
61
|
-
def setup
|
|
62
|
-
@field = Uchi::Field::Number.new(:age)
|
|
63
|
-
@record = Author.new(name: "Test Author")
|
|
64
|
-
@record.define_singleton_method(:age) { 25 }
|
|
65
|
-
@record.define_singleton_method(:age=) { |val| @age = val }
|
|
66
|
-
@repository = Uchi::Repositories::Author.new
|
|
67
|
-
@view_context = ActionController::Base.new.view_context
|
|
68
|
-
|
|
69
|
-
@form = ActionView::Helpers::FormBuilder.new(:author, @record, @view_context, {})
|
|
70
|
-
|
|
71
|
-
@component = Uchi::Field::Number::Edit.new(
|
|
72
|
-
field: @field,
|
|
73
|
-
form: @form,
|
|
74
|
-
hint: "Custom hint",
|
|
75
|
-
label: "Custom label",
|
|
76
|
-
repository: @repository
|
|
77
|
-
)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
test "inherits from Base component" do
|
|
81
|
-
assert_kind_of Uchi::Field::Base::Edit, @component
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
test "renders a number input field with the field content" do
|
|
85
|
-
render_inline(@component)
|
|
86
|
-
|
|
87
|
-
assert_selector("input[name='author[age]']")
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
test "renders label with specified text" do
|
|
91
|
-
render_inline(@component)
|
|
92
|
-
|
|
93
|
-
assert_selector("label", text: "Custom label")
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
test "renders hint when provided" do
|
|
97
|
-
render_inline(@component)
|
|
98
|
-
|
|
99
|
-
assert_selector("p", text: "Custom hint")
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
test "initializes the input component with the correct options" do
|
|
103
|
-
expected_options = {
|
|
104
|
-
attribute: :age,
|
|
105
|
-
form: @form,
|
|
106
|
-
label: {content: "Custom label"},
|
|
107
|
-
hint: {content: "Custom hint"}
|
|
108
|
-
}
|
|
109
|
-
assert_equal expected_options, @component.send(:options)
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
class NumberIndexTest < ViewComponent::TestCase
|
|
114
|
-
def setup
|
|
115
|
-
@field = Uchi::Field::Number.new(:age)
|
|
116
|
-
@record = Author.new(name: "Test Author")
|
|
117
|
-
@record.define_singleton_method(:age) { 25 }
|
|
118
|
-
@repository = Uchi::Repositories::Author.new
|
|
119
|
-
|
|
120
|
-
@component = Uchi::Field::Number::Index.new(
|
|
121
|
-
field: @field,
|
|
122
|
-
record: @record,
|
|
123
|
-
repository: @repository
|
|
124
|
-
)
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
test "inherits from Base component" do
|
|
128
|
-
assert_kind_of Uchi::Field::Base::Index, @component
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
test "renders the field content" do
|
|
132
|
-
result = render_inline(@component)
|
|
133
|
-
|
|
134
|
-
assert_includes result.to_html, "25"
|
|
135
|
-
end
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
class NumberShowTest < ViewComponent::TestCase
|
|
139
|
-
def setup
|
|
140
|
-
@field = Uchi::Field::Number.new(:age)
|
|
141
|
-
@record = Author.new(name: "Test Author")
|
|
142
|
-
@record.define_singleton_method(:age) { 25 }
|
|
143
|
-
@repository = Uchi::Repositories::Author.new
|
|
144
|
-
|
|
145
|
-
@component = Uchi::Field::Number::Show.new(
|
|
146
|
-
field: @field,
|
|
147
|
-
record: @record,
|
|
148
|
-
repository: @repository
|
|
149
|
-
)
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
test "inherits from Base component" do
|
|
153
|
-
assert_kind_of Uchi::Field::Base::Show, @component
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
test "renders the field content" do
|
|
157
|
-
result = render_inline(@component)
|
|
158
|
-
|
|
159
|
-
assert_includes result.to_html, "25"
|
|
160
|
-
end
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
require "ostruct"
|
|
3
|
-
|
|
4
|
-
module Uchi
|
|
5
|
-
class Field
|
|
6
|
-
class StringTest < ActiveSupport::TestCase
|
|
7
|
-
def setup
|
|
8
|
-
@field = Uchi::Field::String.new(:name)
|
|
9
|
-
@form = OpenStruct.new(object: OpenStruct.new(name: "Test Name"))
|
|
10
|
-
@repository = Uchi::Repositories::Author.new
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test "inherits from Uchi::Field" do
|
|
14
|
-
assert_kind_of Uchi::Field, @field
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
test "has default options" do
|
|
18
|
-
assert_equal [:edit, :index, :show], @field.on
|
|
19
|
-
assert @field.searchable?
|
|
20
|
-
assert @field.sortable?
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
test "#edit_component returns an instance of Edit component" do
|
|
24
|
-
component = @field.edit_component(form: @form, hint: "Custom hint", label: "Custom label", repository: @repository)
|
|
25
|
-
assert_equal "Custom hint", component.hint
|
|
26
|
-
assert_equal "Custom label", component.label
|
|
27
|
-
assert_equal @field, component.field
|
|
28
|
-
assert_equal @form, component.form
|
|
29
|
-
assert_equal @repository, component.repository
|
|
30
|
-
assert_kind_of Uchi::Field::String::Edit, component
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
test "#index_component returns an instance of Index component" do
|
|
34
|
-
component = @field.index_component(record: @form.object, repository: @repository)
|
|
35
|
-
assert_equal @field, component.field
|
|
36
|
-
assert_equal @form.object, component.record
|
|
37
|
-
assert_equal @repository, component.repository
|
|
38
|
-
assert_kind_of Uchi::Field::String::Index, component
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
test "#searchable? returns false when explicitly set" do
|
|
42
|
-
field = Uchi::Field::String.new(:name, searchable: false)
|
|
43
|
-
assert_not field.searchable?
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
test "#show_component returns an instance of Show component" do
|
|
47
|
-
component = @field.show_component(record: @form.object, repository: @repository)
|
|
48
|
-
assert_equal @field, component.field
|
|
49
|
-
assert_equal @form.object, component.record
|
|
50
|
-
assert_equal @repository, component.repository
|
|
51
|
-
assert_kind_of Uchi::Field::String::Show, component
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
test "#sortable? returns false when explicitly set" do
|
|
55
|
-
field = Uchi::Field::String.new(:name, sortable: false)
|
|
56
|
-
assert_not field.sortable?
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
class StringEditTest < ViewComponent::TestCase
|
|
61
|
-
def setup
|
|
62
|
-
@field = Uchi::Field::String.new(:name)
|
|
63
|
-
@record = Author.new(name: "J.R.R Tolkien")
|
|
64
|
-
@repository = Uchi::Repositories::Author.new
|
|
65
|
-
@view_context = ActionController::Base.new.view_context
|
|
66
|
-
|
|
67
|
-
@form = ActionView::Helpers::FormBuilder.new(:author, @record, @view_context, {})
|
|
68
|
-
|
|
69
|
-
@component = Uchi::Field::String::Edit.new(
|
|
70
|
-
field: @field,
|
|
71
|
-
form: @form,
|
|
72
|
-
hint: "Custom hint",
|
|
73
|
-
label: "Custom label",
|
|
74
|
-
repository: @repository
|
|
75
|
-
)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
test "inherits from Base component" do
|
|
79
|
-
assert_kind_of Uchi::Field::Base::Edit, @component
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
test "renders an input field with the field content" do
|
|
83
|
-
render_inline(@component)
|
|
84
|
-
|
|
85
|
-
assert_selector("input[type='text'][name='author[name]'][value='J.R.R Tolkien']")
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
test "renders label with specified text" do
|
|
89
|
-
render_inline(@component)
|
|
90
|
-
|
|
91
|
-
assert_selector("label[for='author_name']", text: "Custom label")
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
test "renders hint when provided" do
|
|
95
|
-
render_inline(@component)
|
|
96
|
-
|
|
97
|
-
assert_selector("p[id=author_name_hint]", text: "Custom hint")
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
test "initializes the input component with the correct options" do
|
|
101
|
-
expected_options = {
|
|
102
|
-
attribute: :name,
|
|
103
|
-
form: @form,
|
|
104
|
-
label: {content: "Custom label"},
|
|
105
|
-
hint: {content: "Custom hint"}
|
|
106
|
-
}
|
|
107
|
-
assert_equal expected_options, @component.send(:options)
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
class StringIndexTest < ViewComponent::TestCase
|
|
112
|
-
def setup
|
|
113
|
-
@field = Uchi::Field::String.new(:name)
|
|
114
|
-
@record = Author.new(name: "J.R.R Tolkien")
|
|
115
|
-
@repository = Uchi::Repositories::Author.new
|
|
116
|
-
|
|
117
|
-
@component = Uchi::Field::String::Index.new(
|
|
118
|
-
field: @field,
|
|
119
|
-
record: @record,
|
|
120
|
-
repository: @repository
|
|
121
|
-
)
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
test "inherits from Base component" do
|
|
125
|
-
assert_kind_of Uchi::Field::Base::Index, @component
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
test "renders the field content" do
|
|
129
|
-
result = render_inline(@component)
|
|
130
|
-
|
|
131
|
-
assert_includes result.to_html, "J.R.R Tolkien"
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
class StringShowTest < ViewComponent::TestCase
|
|
136
|
-
def setup
|
|
137
|
-
@field = Uchi::Field::String.new(:name)
|
|
138
|
-
@record = Author.new(name: "J.R.R Tolkien")
|
|
139
|
-
@repository = Uchi::Repositories::Author.new
|
|
140
|
-
|
|
141
|
-
@component = Uchi::Field::String::Show.new(
|
|
142
|
-
field: @field,
|
|
143
|
-
record: @record,
|
|
144
|
-
repository: @repository
|
|
145
|
-
)
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
test "inherits from Base component" do
|
|
149
|
-
assert_kind_of Uchi::Field::Base::Show, @component
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
test "renders the field content" do
|
|
153
|
-
result = render_inline(@component)
|
|
154
|
-
|
|
155
|
-
assert_includes result.to_html, "J.R.R Tolkien"
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
end
|
|
159
|
-
end
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
require "test_helper"
|
|
2
|
-
|
|
3
|
-
module Uchi
|
|
4
|
-
class AuthorsControllerTest < ActionDispatch::IntegrationTest
|
|
5
|
-
setup do
|
|
6
|
-
@author = Author.create!(name: "Test Author")
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
test "GET edit renders successfully" do
|
|
10
|
-
get edit_uchi_author_url(id: @author.id)
|
|
11
|
-
assert_response :success
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
test "GET edit renders the edit view" do
|
|
15
|
-
get edit_uchi_author_url(id: @author.id)
|
|
16
|
-
assert_template :edit
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
test "GET index responds successfully" do
|
|
20
|
-
get uchi_authors_url
|
|
21
|
-
assert_response :success
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
test "GET index renders the index view" do
|
|
25
|
-
get uchi_authors_url
|
|
26
|
-
assert_template :index
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
test "GET new renders successfully" do
|
|
30
|
-
get new_uchi_author_url
|
|
31
|
-
assert_response :success
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
test "GET new renders the new view" do
|
|
35
|
-
get new_uchi_author_url
|
|
36
|
-
assert_template :new
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
test "GET show responds successfully" do
|
|
40
|
-
get uchi_author_url(id: @author.id)
|
|
41
|
-
assert_response :success
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
test "GET show renders the show view" do
|
|
45
|
-
get uchi_author_url(id: @author.id)
|
|
46
|
-
assert_template :show
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
test "PATCH update redirects to show after successful update" do
|
|
50
|
-
patch uchi_author_url(id: @author.id), params: {author: {name: "Updated Name"}}
|
|
51
|
-
assert_redirected_to uchi_author_url(id: @author.id)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
test "PATCH update responds with 303 after successful update" do
|
|
55
|
-
patch uchi_author_url(id: @author.id), params: {author: {name: "Updated Name"}}
|
|
56
|
-
assert_response :see_other
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
test "PATCH update changes the author's attributes" do
|
|
60
|
-
patch uchi_author_url(id: @author.id), params: {author: {name: "Updated Name"}}
|
|
61
|
-
@author.reload
|
|
62
|
-
assert_equal "Updated Name", @author.name
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
test "PATCH update flashes a translated success message after successful update" do
|
|
66
|
-
::I18n.with_locale(:da) do
|
|
67
|
-
patch uchi_author_url(id: @author.id), params: {author: {name: "Updated Name"}}
|
|
68
|
-
assert_equal "Dine ændringer til forfatteren blev gemt", flash[:notice]
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
test "PATCH update falls back to default success message after successful update" do
|
|
73
|
-
patch uchi_author_url(id: @author.id), params: {author: {name: "Updated Name"}}
|
|
74
|
-
assert_equal "Your changes have been saved", flash[:notice]
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
test "PATCH update rerenders the edit view after unsuccessful update" do
|
|
78
|
-
patch uchi_author_url(id: @author.id), params: {author: {name: ""}}
|
|
79
|
-
assert_template :edit
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
test "PATCH responds with 422 after unsuccessful update" do
|
|
83
|
-
patch uchi_author_url(id: @author.id), params: {author: {name: ""}}
|
|
84
|
-
assert_response :unprocessable_entity
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
test "POST create redirects to show after successful creation" do
|
|
88
|
-
post uchi_authors_url, params: {author: {name: "New Author"}}
|
|
89
|
-
assert_redirected_to uchi_author_url(id: Author.last.id)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
test "POST create responds with 303 after successful creation" do
|
|
93
|
-
post uchi_authors_url, params: {author: {name: "New Author"}}
|
|
94
|
-
assert_response :see_other
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
test "POST create flashes a translated success message after successful creation" do
|
|
98
|
-
::I18n.with_locale(:da) do
|
|
99
|
-
post uchi_authors_url, params: {author: {name: "New Author"}}
|
|
100
|
-
assert_equal "Forfatteren er blevet tilføjet", flash[:notice]
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
test "POST create creates a new author" do
|
|
105
|
-
post uchi_authors_url, params: {author: {name: "New Author"}}
|
|
106
|
-
assert_equal "New Author", Author.last.name
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
test "POST create rerenders the new view after unsuccessful creation" do
|
|
110
|
-
post uchi_authors_url, params: {author: {name: ""}}
|
|
111
|
-
assert_template :new
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
test "POST create responds with 422 after unsuccessful creation" do
|
|
115
|
-
post uchi_authors_url, params: {author: {name: ""}}
|
|
116
|
-
assert_response :unprocessable_entity
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
end
|