micro_cms 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +74 -0
  3. data/Rakefile +24 -0
  4. data/app/assets/config/micro_cms_manifest.js +1 -0
  5. data/app/assets/javascripts/micro_cms.js +51 -0
  6. data/app/assets/stylesheets/micro_cms/micro_cms.css +30 -0
  7. data/app/controllers/micro_cms/application_controller.rb +7 -0
  8. data/app/controllers/micro_cms/content_block_controller.rb +31 -0
  9. data/app/helpers/micro_cms/application_helper.rb +6 -0
  10. data/app/helpers/micro_cms/cms_block_helper.rb +28 -0
  11. data/app/models/micro_cms/application_record.rb +7 -0
  12. data/app/models/micro_cms/content_block.rb +26 -0
  13. data/app/views/micro_cms/_content_block.html.erb +19 -0
  14. data/config/routes.rb +5 -0
  15. data/db/migrate/20190923103919_create_micro_cms_content_blocks.rb +12 -0
  16. data/lib/micro_cms.rb +15 -0
  17. data/lib/micro_cms/engine.rb +25 -0
  18. data/lib/micro_cms/version.rb +5 -0
  19. data/spec/dummy/Rakefile +8 -0
  20. data/spec/dummy/app/assets/config/manifest.js +3 -0
  21. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  22. data/spec/dummy/app/channels/application_cable/channel.rb +6 -0
  23. data/spec/dummy/app/channels/application_cable/connection.rb +6 -0
  24. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  25. data/spec/dummy/app/helpers/application_helper.rb +4 -0
  26. data/spec/dummy/app/javascript/packs/application.js +15 -0
  27. data/spec/dummy/app/jobs/application_job.rb +9 -0
  28. data/spec/dummy/app/mailers/application_mailer.rb +6 -0
  29. data/spec/dummy/app/models/application_record.rb +5 -0
  30. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  32. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  33. data/spec/dummy/bin/rails +11 -0
  34. data/spec/dummy/bin/rake +11 -0
  35. data/spec/dummy/bin/rspec +8 -0
  36. data/spec/dummy/bin/setup +35 -0
  37. data/spec/dummy/bin/spring +17 -0
  38. data/spec/dummy/config.ru +7 -0
  39. data/spec/dummy/config/application.rb +31 -0
  40. data/spec/dummy/config/boot.rb +7 -0
  41. data/spec/dummy/config/cable.yml +10 -0
  42. data/spec/dummy/config/database.yml +25 -0
  43. data/spec/dummy/config/environment.rb +7 -0
  44. data/spec/dummy/config/environments/development.rb +64 -0
  45. data/spec/dummy/config/environments/production.rb +114 -0
  46. data/spec/dummy/config/environments/test.rb +50 -0
  47. data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
  48. data/spec/dummy/config/initializers/assets.rb +14 -0
  49. data/spec/dummy/config/initializers/backtrace_silencers.rb +9 -0
  50. data/spec/dummy/config/initializers/content_security_policy.rb +30 -0
  51. data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
  52. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  53. data/spec/dummy/config/initializers/inflections.rb +18 -0
  54. data/spec/dummy/config/initializers/mime_types.rb +6 -0
  55. data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
  56. data/spec/dummy/config/locales/en.yml +33 -0
  57. data/spec/dummy/config/puma.rb +40 -0
  58. data/spec/dummy/config/routes.rb +5 -0
  59. data/spec/dummy/config/spring.rb +8 -0
  60. data/spec/dummy/config/storage.yml +34 -0
  61. data/spec/dummy/db/development.sqlite3 +0 -0
  62. data/spec/dummy/db/migrate/20190923150252_create_micro_cms_content_blocks.micro_cms.rb +13 -0
  63. data/spec/dummy/db/schema.rb +22 -0
  64. data/spec/dummy/db/test.sqlite3 +0 -0
  65. data/spec/dummy/log/development.log +1 -0
  66. data/spec/dummy/log/test.log +478 -0
  67. data/spec/dummy/public/404.html +67 -0
  68. data/spec/dummy/public/422.html +67 -0
  69. data/spec/dummy/public/500.html +66 -0
  70. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  71. data/spec/dummy/public/apple-touch-icon.png +0 -0
  72. data/spec/dummy/public/favicon.ico +0 -0
  73. data/spec/dummy/tmp/development_secret.txt +1 -0
  74. data/spec/engine/micro_cms_spec.rb +9 -0
  75. data/spec/examples.txt +28 -0
  76. data/spec/factories/micro_cms/content_blocks.rb +8 -0
  77. data/spec/helpers/micro_cms/cms_block_helper_spec.rb +138 -0
  78. data/spec/models/micro_cms/content_block_spec.rb +62 -0
  79. data/spec/rails_helper.rb +75 -0
  80. data/spec/requests/micro_cms/content_block_controller_spec.rb +57 -0
  81. data/spec/routing/micro_cms/content_blocks_routing_spec.rb +17 -0
  82. data/spec/spec_helper.rb +43 -0
  83. data/spec/support/shared_examples/cms_block_helper_spec_helper.rb +9 -0
  84. data/spec/views/micro_cms/content_block_spec.rb +25 -0
  85. metadata +250 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ .rails-default-error-page {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ .rails-default-error-page div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ .rails-default-error-page div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ .rails-default-error-page h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ .rails-default-error-page div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body class="rails-default-error-page">
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
File without changes
@@ -0,0 +1 @@
1
+ 638a8ed4fb8252b2f79ceb879bb053cc8c8168698501f04426d68dd62586743b6534a65ded165fa22ab7425c4a1c15c1c16a63838b4b209edc38686aec8e1481
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe MicroCms do
4
+ describe '#self.configure' do
5
+ it 'yields the class back' do
6
+ expect { |block| described_class.configure(&block) }.to yield_with_args described_class
7
+ end
8
+ end
9
+ end
data/spec/examples.txt ADDED
@@ -0,0 +1,28 @@
1
+ example_id | status | run_time |
2
+ --------------------------------------------------------------------- | ------- | --------------- |
3
+ ./spec/engine/micro_cms_spec.rb[1:1:1] | passed | 0.01991 seconds |
4
+ ./spec/helpers/micro_cms/cms_block_helper_spec.rb[1:1:1:1:1] | passed | 0.02075 seconds |
5
+ ./spec/helpers/micro_cms/cms_block_helper_spec.rb[1:1:1:2:1:1] | passed | 0.00998 seconds |
6
+ ./spec/helpers/micro_cms/cms_block_helper_spec.rb[1:1:1:3:1:1] | passed | 0.09654 seconds |
7
+ ./spec/helpers/micro_cms/cms_block_helper_spec.rb[1:1:1:4:1:1] | passed | 0.01025 seconds |
8
+ ./spec/helpers/micro_cms/cms_block_helper_spec.rb[1:1:2:1:1] | passed | 0.00707 seconds |
9
+ ./spec/helpers/micro_cms/cms_block_helper_spec.rb[1:2:1:1] | passed | 0.11106 seconds |
10
+ ./spec/helpers/micro_cms/cms_block_helper_spec.rb[1:2:2:1:1:1] | unknown | |
11
+ ./spec/helpers/micro_cms/cms_block_helper_spec.rb[1:2:2:2:1:1] | passed | 0.0555 seconds |
12
+ ./spec/helpers/micro_cms/cms_block_helper_spec.rb[1:2:2:3:1:1] | passed | 0.08544 seconds |
13
+ ./spec/models/micro_cms/content_block_spec.rb[1:1:1] | passed | 0.01632 seconds |
14
+ ./spec/models/micro_cms/content_block_spec.rb[1:1:2] | passed | 0.00248 seconds |
15
+ ./spec/models/micro_cms/content_block_spec.rb[1:2:1] | passed | 0.00164 seconds |
16
+ ./spec/models/micro_cms/content_block_spec.rb[1:3:1] | passed | 0.0314 seconds |
17
+ ./spec/models/micro_cms/content_block_spec.rb[1:4:1:1] | passed | 0.00415 seconds |
18
+ ./spec/models/micro_cms/content_block_spec.rb[1:4:2:1] | passed | 0.01077 seconds |
19
+ ./spec/models/micro_cms/content_block_spec.rb[1:5:1] | passed | 0.00118 seconds |
20
+ ./spec/requests/micro_cms/content_block_controller_spec.rb[1:1:1:1] | passed | 0.24317 seconds |
21
+ ./spec/requests/micro_cms/content_block_controller_spec.rb[1:1:1:2:1] | passed | 0.01317 seconds |
22
+ ./spec/requests/micro_cms/content_block_controller_spec.rb[1:1:2:1] | passed | 0.00883 seconds |
23
+ ./spec/routing/micro_cms/content_blocks_routing_spec.rb[1:1:1] | passed | 0.00197 seconds |
24
+ ./spec/routing/micro_cms/content_blocks_routing_spec.rb[1:1:2] | passed | 0.00338 seconds |
25
+ ./spec/views/micro_cms/content_block_spec.rb[1:1] | passed | 0.01204 seconds |
26
+ ./spec/views/micro_cms/content_block_spec.rb[1:2] | passed | 0.02707 seconds |
27
+ ./spec/views/micro_cms/content_block_spec.rb[1:3] | passed | 0.0134 seconds |
28
+ ./spec/views/micro_cms/content_block_spec.rb[1:4] | passed | 0.01026 seconds |
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ FactoryBot.define do
4
+ factory :micro_cms_content_block, class: MicroCms::ContentBlock do
5
+ path { 'my-path-de' }
6
+ content { 'MyText' }
7
+ end
8
+ end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe MicroCms::CmsBlockHelper, type: :helper do
6
+ let(:created_content_block) { MicroCms::ContentBlock.order(:created_at).last }
7
+
8
+ let(:sample_default_template) do
9
+ ERB.new <<-ERB.chomp
10
+ <p>This is my custom content</p>
11
+ ERB
12
+ end
13
+
14
+ describe '#cms_block' do
15
+ subject(:cms_block) { helper.cms_block(path, default) }
16
+
17
+ let(:path) { 'my.custom.path' }
18
+ let(:default) { nil }
19
+ let(:subject_method) { cms_block }
20
+
21
+ context 'when the content block does not exist' do
22
+ describe 'rendered partial' do
23
+ let(:partial_params) do
24
+ { partial: 'micro_cms/content_block', locals: { content_block: created_content_block } }
25
+ end
26
+
27
+ before do
28
+ allow(helper).to receive(:render)
29
+ cms_block
30
+ end
31
+
32
+ it 'renders the correct partial' do
33
+ expect(helper).to have_received(:render).with(partial_params)
34
+ end
35
+ end
36
+
37
+ context 'when a block is given' do
38
+ subject(:cms_block) do
39
+ helper.cms_block(path, &sample_default_template.method(:result))
40
+ end
41
+
42
+ it_behaves_like 'creates a new content block at the given path' do
43
+ let(:content) { ERB::Util.html_escape sample_default_template.result }
44
+ let(:content_block) { created_content_block }
45
+ end
46
+ end
47
+
48
+ context 'when a default param is given' do
49
+ let(:default) { 'my default value' }
50
+
51
+ it_behaves_like 'creates a new content block at the given path' do
52
+ let(:content) { default }
53
+ let(:content_block) { created_content_block }
54
+ end
55
+ end
56
+
57
+ context 'when no default is given' do
58
+ it_behaves_like 'creates a new content block at the given path' do
59
+ let(:content) { '' }
60
+ let(:content_block) { created_content_block }
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'when the block does already exist' do
66
+ let!(:content_block) { create :micro_cms_content_block, path: MicroCms::ContentBlock.format_path(path) }
67
+ let(:path) { 'my.custom.path' }
68
+
69
+ describe 'rendered partial' do
70
+ let(:partial_params) do
71
+ { partial: 'micro_cms/content_block', locals: { content_block: content_block } }
72
+ end
73
+
74
+ before do
75
+ allow(helper).to receive(:render)
76
+ end
77
+
78
+ it 'renders the correct partial' do
79
+ helper.cms_block(path)
80
+ expect(helper).to have_received(:render).with(partial_params)
81
+ end
82
+ end
83
+ end
84
+ end
85
+
86
+ describe '#cms_content' do
87
+ subject(:cms_content) { helper.cms_content(path, default) }
88
+
89
+ let(:subject_method) { cms_content }
90
+ let(:default) { 'my default' }
91
+
92
+ context 'when the content block already exists' do
93
+ let(:formatted_path) { MicroCms::ContentBlock.format_path(path) }
94
+ let(:path) { 'my.custom.path' }
95
+ let(:content) { 'my custom content of the block' }
96
+
97
+ before { create :micro_cms_content_block, path: formatted_path, content: content }
98
+
99
+ it 'renders the content', :aggregate_failures do
100
+ expect(cms_content).to include content
101
+ expect(cms_content).not_to include 'contenteditable'
102
+ end
103
+ end
104
+
105
+ context 'when the content block does not exist yet' do
106
+ let(:path) { 'my.nonexistent.path' }
107
+
108
+ context 'when the default param is given' do
109
+ let(:default) { 'my default value' }
110
+
111
+ it_behaves_like 'creates a new content block at the given path' do
112
+ let(:content) { default }
113
+ let(:content_block) { created_content_block }
114
+ end
115
+ end
116
+
117
+ context 'when a default block is given' do
118
+ subject(:cms_content) do
119
+ helper.cms_content(path, &sample_default_template.method(:result))
120
+ end
121
+
122
+ it_behaves_like 'creates a new content block at the given path' do
123
+ let(:content) { ERB::Util.html_escape sample_default_template.result }
124
+ let(:content_block) { created_content_block }
125
+ end
126
+ end
127
+
128
+ context 'when no default is given' do
129
+ let(:default) { nil }
130
+
131
+ it_behaves_like 'creates a new content block at the given path' do
132
+ let(:content) { '' }
133
+ let(:content_block) { created_content_block }
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe MicroCms::ContentBlock, type: :model do
6
+ describe 'validations' do
7
+ it { is_expected.to validate_presence_of :path }
8
+ it { is_expected.to validate_exclusion_of(:content).in_array([nil]) }
9
+ end
10
+
11
+ describe '#self.table_name_prefix' do
12
+ it 'prefixes db table name' do
13
+ expect(described_class.table_name_prefix).to eq 'micro_cms_'
14
+ end
15
+ end
16
+
17
+ describe '#self.format_path' do
18
+ subject(:formatted_path) { described_class.format_path(i18n_key) }
19
+
20
+ let(:i18n_key) { 'my.key.to.success' }
21
+
22
+ before { I18n.locale = :en }
23
+
24
+ after { I18n.locale = I18n.default_locale }
25
+
26
+ it 'returns the formatted path' do
27
+ expect(formatted_path).to eq 'my-key-to-success-en'
28
+ end
29
+ end
30
+
31
+ describe '#self.content_block_for_path' do
32
+ let(:path) { 'my.content.block' }
33
+
34
+ context 'when the content block already exists' do
35
+ let!(:content_block) { create :micro_cms_content_block, path: described_class.format_path(path) }
36
+
37
+ it 'returns the content block for the given path' do
38
+ expect(described_class.content_block_for_path(path)).to eq content_block
39
+ end
40
+ end
41
+
42
+ context 'when the content block does not exist yet' do
43
+ subject(:create_content_block) { described_class.content_block_for_path(path, content: new_content) }
44
+
45
+ let(:new_content) { 'my content' }
46
+ let(:formatted_path) { described_class.format_path path }
47
+ let(:created_content_block) { described_class.order(:created_at).last }
48
+
49
+ it 'creates a new one with default params', :aggregate_failures do
50
+ expect { create_content_block }.to change(described_class, :count)
51
+ expect(created_content_block.path).to eq formatted_path
52
+ expect(created_content_block.content).to eq new_content
53
+ end
54
+ end
55
+ end
56
+
57
+ describe '#to_param' do
58
+ subject { build(:micro_cms_content_block, path: 'my-path-de').to_param }
59
+
60
+ it { is_expected.to eq 'my-path-de' }
61
+ end
62
+ end