compony 0.11.14 → 0.12.0

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.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -0
  3. data/Gemfile.lock +1 -1
  4. data/VERSION +1 -1
  5. data/compony.gemspec +3 -3
  6. data/config/locales/de.yml +1 -1
  7. data/config/locales/en.yml +1 -1
  8. data/config/locales/es.yml +1 -1
  9. data/config/locales/fr.yml +1 -1
  10. data/doc/ComponentGenerator.html +1 -1
  11. data/doc/Components.html +1 -1
  12. data/doc/ComponentsGenerator.html +1 -1
  13. data/doc/Compony/Component.html +1 -1
  14. data/doc/Compony/ComponentMixins/Default/Labelling.html +1 -1
  15. data/doc/Compony/ComponentMixins/Default/Standalone/ResourcefulVerbDsl.html +1 -1
  16. data/doc/Compony/ComponentMixins/Default/Standalone/StandaloneDsl.html +1 -1
  17. data/doc/Compony/ComponentMixins/Default/Standalone/VerbDsl.html +1 -1
  18. data/doc/Compony/ComponentMixins/Default/Standalone.html +1 -1
  19. data/doc/Compony/ComponentMixins/Default.html +1 -1
  20. data/doc/Compony/ComponentMixins/Resourceful.html +1 -1
  21. data/doc/Compony/ComponentMixins.html +1 -1
  22. data/doc/Compony/Components/Buttons/CssButton.html +12 -1
  23. data/doc/Compony/Components/Buttons/Link.html +239 -16
  24. data/doc/Compony/Components/Buttons.html +1 -1
  25. data/doc/Compony/Components/Destroy.html +1 -1
  26. data/doc/Compony/Components/Edit.html +1 -1
  27. data/doc/Compony/Components/Form.html +83 -83
  28. data/doc/Compony/Components/Index.html +1 -1
  29. data/doc/Compony/Components/List.html +1 -1
  30. data/doc/Compony/Components/New.html +1 -1
  31. data/doc/Compony/Components/Show.html +1 -1
  32. data/doc/Compony/Components/WithForm.html +1 -1
  33. data/doc/Compony/Components.html +1 -1
  34. data/doc/Compony/ControllerMixin.html +1 -1
  35. data/doc/Compony/Engine.html +1 -1
  36. data/doc/Compony/Intent.html +1 -1
  37. data/doc/Compony/ManageIntentsDsl.html +1 -1
  38. data/doc/Compony/MethodAccessibleHash.html +1 -1
  39. data/doc/Compony/ModelFields/Anchormodel.html +1 -1
  40. data/doc/Compony/ModelFields/Association.html +1 -1
  41. data/doc/Compony/ModelFields/Attachment.html +13 -11
  42. data/doc/Compony/ModelFields/Base.html +1 -1
  43. data/doc/Compony/ModelFields/Boolean.html +1 -1
  44. data/doc/Compony/ModelFields/Color.html +1 -1
  45. data/doc/Compony/ModelFields/Currency.html +1 -1
  46. data/doc/Compony/ModelFields/Date.html +1 -1
  47. data/doc/Compony/ModelFields/Datetime.html +1 -1
  48. data/doc/Compony/ModelFields/Decimal.html +1 -1
  49. data/doc/Compony/ModelFields/Email.html +1 -1
  50. data/doc/Compony/ModelFields/Float.html +1 -1
  51. data/doc/Compony/ModelFields/Integer.html +1 -1
  52. data/doc/Compony/ModelFields/Percentage.html +1 -1
  53. data/doc/Compony/ModelFields/Phone.html +1 -1
  54. data/doc/Compony/ModelFields/RichText.html +1 -1
  55. data/doc/Compony/ModelFields/String.html +1 -1
  56. data/doc/Compony/ModelFields/Text.html +1 -1
  57. data/doc/Compony/ModelFields/Time.html +1 -1
  58. data/doc/Compony/ModelFields/Url.html +1 -1
  59. data/doc/Compony/ModelFields.html +1 -1
  60. data/doc/Compony/ModelMixin.html +1 -1
  61. data/doc/Compony/NaturalOrdering.html +1 -1
  62. data/doc/Compony/RequestContext.html +1 -1
  63. data/doc/Compony/Version.html +1 -1
  64. data/doc/Compony/ViewHelpers.html +1 -1
  65. data/doc/Compony/VirtualModel.html +1 -1
  66. data/doc/Compony.html +1 -1
  67. data/doc/ComponyController.html +1 -1
  68. data/doc/_index.html +1 -1
  69. data/doc/file.CHANGELOG.html +32 -9
  70. data/doc/file.README.html +1 -1
  71. data/doc/file.basic_component.html +1 -1
  72. data/doc/file.cookbook.html +1 -1
  73. data/doc/file.destroy.html +1 -1
  74. data/doc/file.dsl_reference.html +1 -1
  75. data/doc/file.edit.html +1 -1
  76. data/doc/file.example.html +1 -1
  77. data/doc/file.example_advanced.html +1 -1
  78. data/doc/file.feasibility.html +1 -1
  79. data/doc/file.form.html +1 -1
  80. data/doc/file.generators.html +1 -1
  81. data/doc/file.glossary.html +1 -1
  82. data/doc/file.gotchas.html +1 -1
  83. data/doc/file.index.html +1 -1
  84. data/doc/file.inheritance.html +1 -1
  85. data/doc/file.installation.html +1 -1
  86. data/doc/file.integrations.html +32 -2
  87. data/doc/file.intents.html +8 -4
  88. data/doc/file.internal_datastructures.html +1 -1
  89. data/doc/file.list.html +3 -1
  90. data/doc/file.maintaining.html +1 -1
  91. data/doc/file.model_fields.html +1 -1
  92. data/doc/file.nesting.html +1 -1
  93. data/doc/file.new.html +1 -1
  94. data/doc/file.ownership.html +1 -1
  95. data/doc/file.patterns.html +1 -1
  96. data/doc/file.pre_built_components.html +1 -1
  97. data/doc/file.resourceful.html +1 -1
  98. data/doc/file.show.html +1 -1
  99. data/doc/file.standalone.html +1 -1
  100. data/doc/file.virtual_models.html +1 -1
  101. data/doc/file.with_form.html +1 -1
  102. data/doc/guide/intents.md +6 -3
  103. data/doc/guide/pre_built_components/list.md +4 -0
  104. data/doc/index.html +1 -1
  105. data/doc/integrations.md +46 -1
  106. data/doc/method_list.html +69 -53
  107. data/doc/top-level-namespace.html +1 -1
  108. data/lib/compony/components/buttons/link.rb +37 -2
  109. data/lib/compony/components/form.rb +2 -6
  110. data/lib/compony/model_fields/attachment.rb +7 -6
  111. data/spec/compony/components/buttons/link_spec.rb +73 -0
  112. data/spec/compony/model_fields/attachment_spec.rb +41 -0
  113. data/spec/requests/users_crud_spec.rb +7 -0
  114. metadata +3 -1
@@ -0,0 +1,73 @@
1
+ RSpec.describe Compony::Components::Buttons::Link do
2
+ let(:controller) do
3
+ ApplicationController.new.tap do |c|
4
+ c.request = ActionDispatch::TestRequest.create
5
+ c.response = ActionDispatch::TestResponse.new
6
+ end
7
+ end
8
+
9
+ # Outside a request, the controller reports a body, which would make the component skip rendering.
10
+ before { allow(controller).to receive(:response_body).and_return(nil) }
11
+
12
+ def render_button(klass = described_class, **)
13
+ klass.new(**).render(controller)
14
+ end
15
+
16
+ it 'renders a link to the given href' do
17
+ expect(render_button(label: 'Go', href: '/users')).to eq('<a href="/users">Go</a>')
18
+ end
19
+
20
+ it 'renders an <a> without href (and without a javascript: URL) when no href is given' do
21
+ expect(render_button(label: 'Nothing')).to eq('<a>Nothing</a>')
22
+ end
23
+
24
+ it 'renders a submit button when given type: :submit' do
25
+ expect(render_button(label: 'Save', type: :submit, class: 'primary')).to eq('<button class="primary" type="submit">Save</button>')
26
+ end
27
+
28
+ it 'renders a disabled submit button when given the class disabled' do
29
+ expect(render_button(label: 'Save', type: :submit, class: 'disabled')).to include('disabled="disabled"')
30
+ end
31
+
32
+ it 'never renders inline JavaScript' do
33
+ [{ label: 'a' }, { label: 'b', href: '/x' }, { label: 'c', type: :submit }, { label: 'd', class: 'disabled' }].each do |opts|
34
+ expect(render_button(**opts)).not_to match(/javascript:|\bon[a-z]+=/)
35
+ end
36
+ end
37
+
38
+ describe 'button styles overriding content' do
39
+ let(:rendering_through_helper) do
40
+ Class.new(described_class) do
41
+ def self.name = 'HelperButton'
42
+ setup do
43
+ content do
44
+ concat component.link_or_button(capture { span @label }, **@comp_opts, class: 'fancy')
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ let(:calling_link_to) do
51
+ Class.new(described_class) do
52
+ def self.name = 'LegacyButton'
53
+ setup do
54
+ content do
55
+ concat link_to(@label, @href, **@comp_opts)
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ it 'can render a submit button through link_or_button' do
62
+ expect(render_button(rendering_through_helper, label: 'Save', type: :submit)).to eq('<button class="fancy" type="submit"><span>Save</span></button>')
63
+ end
64
+
65
+ it 'keeps the former markup when calling link_to without a href' do
66
+ expect(render_button(calling_link_to, label: 'Nothing')).to eq('<a href="javascript:void(0)">Nothing</a>')
67
+ end
68
+
69
+ it 'fails loudly when given a type but rendering a link' do
70
+ expect { render_button(calling_link_to, label: 'Save', type: :submit) }.to raise_error(/did not render through `link_or_button`/)
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,41 @@
1
+ RSpec.describe Compony::ModelFields::Attachment do
2
+ # The dummy app does not load Active Storage, so the attachment reflection and the attachments are stand-ins.
3
+ let(:many_reflection_class) { Class.new }
4
+ let(:model_class) do
5
+ reflection = many_reflection_class.new
6
+ Class.new { define_singleton_method(:reflect_on_attachment) { |_name| reflection } }
7
+ end
8
+ let(:attachments) do
9
+ [
10
+ double(id: 1, signed_id: 'signed-1', filename: 'one.pdf'),
11
+ double(id: 2, signed_id: 'signed-2', filename: 'two.pdf')
12
+ ]
13
+ end
14
+ let(:record) do
15
+ double(new_record?: false, model_name: ActiveModel::Name.new(User), files: attachments)
16
+ end
17
+ let(:form) do
18
+ double(object: record).tap do |form|
19
+ helpers = ActionController::Base.helpers
20
+ allow(form).to receive(:label) { |name| helpers.label_tag(name) }
21
+ allow(form).to receive(:input) { |name, **| helpers.file_field_tag("user[#{name}][]") }
22
+ end
23
+ end
24
+
25
+ before { stub_const('ActiveStorage::Reflection::HasManyAttachedReflection', many_reflection_class) }
26
+
27
+ describe 'simpleform_input of an existing record with several attachments' do
28
+ subject(:html) { described_class.new(:files, model_class).simpleform_input(form, nil) }
29
+
30
+ it 'submits each present attachment through a checked checkbox, so unticking it removes the attachment' do
31
+ expect(html).to include('<input type="checkbox" name="user[files][]" id="user_files_keep_1" value="signed-1"')
32
+ expect(html).to include('<input type="checkbox" name="user[files][]" id="user_files_keep_2" value="signed-2"')
33
+ expect(html.scan('checked="checked"').size).to eq(2)
34
+ expect(html).to include('<label class="compony-attachments-filename" for="user_files_keep_1">one.pdf</label>')
35
+ end
36
+
37
+ it 'renders no inline JavaScript' do
38
+ expect(html).not_to match(/javascript:|\bon[a-z]+=/)
39
+ end
40
+ end
41
+ end
@@ -40,6 +40,13 @@ RSpec.describe 'Users CRUD via pre-built components', type: :request do
40
40
  expect(response.body).to include('user[age]')
41
41
  end
42
42
 
43
+ it 'renders a real submit button and no inline JavaScript, so it works under a Content Security Policy' do
44
+ get '/users/new'
45
+ expect(response.body.scan('type="submit"').size).to eq(1)
46
+ expect(response.body).to match(%r{<button[^>]* type="submit">Submit</button>})
47
+ expect(response.body).not_to match(/javascript:|\bon[a-z]+=/)
48
+ end
49
+
43
50
  it 'creates a user and redirects' do
44
51
  expect do
45
52
  post '/users/new', params: { user: { name: 'Bob', age: '25', comment: 'New guy', email: 'bob@example.com', admin: '0', born_on: '2000-01-01' } }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: compony
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.14
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sandro Kalbermatter
@@ -427,10 +427,12 @@ files:
427
427
  - logo.svg
428
428
  - spec/README.md
429
429
  - spec/compony/component_spec.rb
430
+ - spec/compony/components/buttons/link_spec.rb
430
431
  - spec/compony/components/form_spec.rb
431
432
  - spec/compony/compony_spec.rb
432
433
  - spec/compony/intent_spec.rb
433
434
  - spec/compony/method_accessible_hash_spec.rb
435
+ - spec/compony/model_fields/attachment_spec.rb
434
436
  - spec/compony/model_fields_spec.rb
435
437
  - spec/compony/model_mixin_spec.rb
436
438
  - spec/compony/natural_ordering_spec.rb