nocms-blocks 1.0.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.
- checksums.yaml +7 -0
- data/CHANGELOG +8 -0
- data/LICENSE +674 -0
- data/README.md +233 -0
- data/Rakefile +22 -0
- data/app/assets/javascripts/no_cms/blocks/application.js +13 -0
- data/app/assets/stylesheets/no_cms/blocks/application.css +13 -0
- data/app/controllers/no_cms/blocks/application_controller.rb +4 -0
- data/app/decorators/models/no_cms/blocks/block_decorator.rb +3 -0
- data/app/helpers/no_cms/blocks/application_helper.rb +4 -0
- data/app/helpers/no_cms/blocks/blocks_helper.rb +28 -0
- data/app/models/no_cms/blocks/block.rb +160 -0
- data/app/models/no_cms/blocks/concerns/translation_scopes.rb +16 -0
- data/app/views/layouts/no_cms/blocks/application.html.erb +14 -0
- data/app/views/no_cms/admin/blocks/blocks/_default.html.erb +9 -0
- data/app/views/no_cms/admin/blocks/blocks/_form.html.erb +25 -0
- data/app/views/no_cms/admin/blocks/blocks/_index.html.erb +15 -0
- data/app/views/no_cms/admin/blocks/blocks/_nested_index.html.erb +17 -0
- data/app/views/no_cms/blocks/blocks/_default.html.erb +8 -0
- data/config/locales/en.yml +15 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20140405135410_create_no_cms_blocks_blocks.rb +21 -0
- data/db/migrate/20140405150944_add_awesome_nested_set_to_no_cms_blocks.rb +8 -0
- data/db/migrate/20140618150651_add_position_to_no_cms_blocks_block.rb +5 -0
- data/lib/generators/nocms/blocks_generator.rb +15 -0
- data/lib/generators/nocms/templates/config/initializers/nocms/blocks.rb +43 -0
- data/lib/no_cms/blocks/configuration.rb +20 -0
- data/lib/no_cms/blocks/engine.rb +17 -0
- data/lib/no_cms/blocks/version.rb +5 -0
- data/lib/nocms-blocks.rb +7 -0
- data/lib/tasks/no_cms/blocks.rake +4 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +8 -0
- data/spec/dummy/app/controllers/home_controller.rb +3 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/models/test_image.rb +5 -0
- data/spec/dummy/app/uploaders/logo_uploader.rb +51 -0
- data/spec/dummy/app/views/home/show.html.erb +3 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/no_cms/blocks/blocks/_logo_caption.html.erb +5 -0
- data/spec/dummy/app/views/no_cms/blocks/blocks/_title_3_columns.html.erb +6 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +22 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +38 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/nocms/blocks.rb +43 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +5 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20140304094052_create_test_images.rb +9 -0
- data/spec/dummy/db/schema.rb +43 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +40 -0
- data/spec/dummy/log/test.log +33500 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/uploads/test_image/logo/1/logo.png +0 -0
- data/spec/dummy/public/uploads/test_image/logo/1/logo2.png +0 -0
- data/spec/factories/no_cms/blocks/block.rb +8 -0
- data/spec/factories/test_image.rb +12 -0
- data/spec/fixtures/images/logo.png +0 -0
- data/spec/fixtures/images/logo2.png +0 -0
- data/spec/models/no_cms/blocks/block_spec.rb +200 -0
- data/spec/requests/no_cms/blocks/blocks_spec.rb +95 -0
- data/spec/spec_helper.rb +70 -0
- data/spec/support/concerns/model_with_has_many_relationship.rb +39 -0
- data/spec/support/concerns/model_with_required_attributes.rb +21 -0
- metadata +236 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>The page you were looking for doesn't exist (404)</title>
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
background-color: #EFEFEF;
|
|
8
|
+
color: #2E2F30;
|
|
9
|
+
text-align: center;
|
|
10
|
+
font-family: arial, sans-serif;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
div.dialog {
|
|
14
|
+
width: 25em;
|
|
15
|
+
margin: 4em auto 0 auto;
|
|
16
|
+
border: 1px solid #CCC;
|
|
17
|
+
border-right-color: #999;
|
|
18
|
+
border-left-color: #999;
|
|
19
|
+
border-bottom-color: #BBB;
|
|
20
|
+
border-top: #B00100 solid 4px;
|
|
21
|
+
border-top-left-radius: 9px;
|
|
22
|
+
border-top-right-radius: 9px;
|
|
23
|
+
background-color: white;
|
|
24
|
+
padding: 7px 4em 0 4em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
h1 {
|
|
28
|
+
font-size: 100%;
|
|
29
|
+
color: #730E15;
|
|
30
|
+
line-height: 1.5em;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
body > p {
|
|
34
|
+
width: 33em;
|
|
35
|
+
margin: 0 auto 1em;
|
|
36
|
+
padding: 1em 0;
|
|
37
|
+
background-color: #F7F7F7;
|
|
38
|
+
border: 1px solid #CCC;
|
|
39
|
+
border-right-color: #999;
|
|
40
|
+
border-bottom-color: #999;
|
|
41
|
+
border-bottom-left-radius: 4px;
|
|
42
|
+
border-bottom-right-radius: 4px;
|
|
43
|
+
border-top-color: #DADADA;
|
|
44
|
+
color: #666;
|
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
|
46
|
+
}
|
|
47
|
+
</style>
|
|
48
|
+
</head>
|
|
49
|
+
|
|
50
|
+
<body>
|
|
51
|
+
<!-- This file lives in public/404.html -->
|
|
52
|
+
<div class="dialog">
|
|
53
|
+
<h1>The page you were looking for doesn't exist.</h1>
|
|
54
|
+
<p>You may have mistyped the address or the page may have moved.</p>
|
|
55
|
+
</div>
|
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
57
|
+
</body>
|
|
58
|
+
</html>
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>The change you wanted was rejected (422)</title>
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
background-color: #EFEFEF;
|
|
8
|
+
color: #2E2F30;
|
|
9
|
+
text-align: center;
|
|
10
|
+
font-family: arial, sans-serif;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
div.dialog {
|
|
14
|
+
width: 25em;
|
|
15
|
+
margin: 4em auto 0 auto;
|
|
16
|
+
border: 1px solid #CCC;
|
|
17
|
+
border-right-color: #999;
|
|
18
|
+
border-left-color: #999;
|
|
19
|
+
border-bottom-color: #BBB;
|
|
20
|
+
border-top: #B00100 solid 4px;
|
|
21
|
+
border-top-left-radius: 9px;
|
|
22
|
+
border-top-right-radius: 9px;
|
|
23
|
+
background-color: white;
|
|
24
|
+
padding: 7px 4em 0 4em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
h1 {
|
|
28
|
+
font-size: 100%;
|
|
29
|
+
color: #730E15;
|
|
30
|
+
line-height: 1.5em;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
body > p {
|
|
34
|
+
width: 33em;
|
|
35
|
+
margin: 0 auto 1em;
|
|
36
|
+
padding: 1em 0;
|
|
37
|
+
background-color: #F7F7F7;
|
|
38
|
+
border: 1px solid #CCC;
|
|
39
|
+
border-right-color: #999;
|
|
40
|
+
border-bottom-color: #999;
|
|
41
|
+
border-bottom-left-radius: 4px;
|
|
42
|
+
border-bottom-right-radius: 4px;
|
|
43
|
+
border-top-color: #DADADA;
|
|
44
|
+
color: #666;
|
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
|
46
|
+
}
|
|
47
|
+
</style>
|
|
48
|
+
</head>
|
|
49
|
+
|
|
50
|
+
<body>
|
|
51
|
+
<!-- This file lives in public/422.html -->
|
|
52
|
+
<div class="dialog">
|
|
53
|
+
<h1>The change you wanted was rejected.</h1>
|
|
54
|
+
<p>Maybe you tried to change something you didn't have access to.</p>
|
|
55
|
+
</div>
|
|
56
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
57
|
+
</body>
|
|
58
|
+
</html>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>We're sorry, but something went wrong (500)</title>
|
|
5
|
+
<style>
|
|
6
|
+
body {
|
|
7
|
+
background-color: #EFEFEF;
|
|
8
|
+
color: #2E2F30;
|
|
9
|
+
text-align: center;
|
|
10
|
+
font-family: arial, sans-serif;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
div.dialog {
|
|
14
|
+
width: 25em;
|
|
15
|
+
margin: 4em auto 0 auto;
|
|
16
|
+
border: 1px solid #CCC;
|
|
17
|
+
border-right-color: #999;
|
|
18
|
+
border-left-color: #999;
|
|
19
|
+
border-bottom-color: #BBB;
|
|
20
|
+
border-top: #B00100 solid 4px;
|
|
21
|
+
border-top-left-radius: 9px;
|
|
22
|
+
border-top-right-radius: 9px;
|
|
23
|
+
background-color: white;
|
|
24
|
+
padding: 7px 4em 0 4em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
h1 {
|
|
28
|
+
font-size: 100%;
|
|
29
|
+
color: #730E15;
|
|
30
|
+
line-height: 1.5em;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
body > p {
|
|
34
|
+
width: 33em;
|
|
35
|
+
margin: 0 auto 1em;
|
|
36
|
+
padding: 1em 0;
|
|
37
|
+
background-color: #F7F7F7;
|
|
38
|
+
border: 1px solid #CCC;
|
|
39
|
+
border-right-color: #999;
|
|
40
|
+
border-bottom-color: #999;
|
|
41
|
+
border-bottom-left-radius: 4px;
|
|
42
|
+
border-bottom-right-radius: 4px;
|
|
43
|
+
border-top-color: #DADADA;
|
|
44
|
+
color: #666;
|
|
45
|
+
box-shadow:0 3px 8px rgba(50, 50, 50, 0.17);
|
|
46
|
+
}
|
|
47
|
+
</style>
|
|
48
|
+
</head>
|
|
49
|
+
|
|
50
|
+
<body>
|
|
51
|
+
<!-- This file lives in public/500.html -->
|
|
52
|
+
<div class="dialog">
|
|
53
|
+
<h1>We're sorry, but something went wrong.</h1>
|
|
54
|
+
</div>
|
|
55
|
+
<p>If you are the application owner check the logs for more information.</p>
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Read about factories at https://github.com/thoughtbot/factory_girl
|
|
2
|
+
|
|
3
|
+
FactoryGirl.define do
|
|
4
|
+
factory :test_image, class: TestImage do
|
|
5
|
+
name { Faker::Lorem.sentence }
|
|
6
|
+
logo { File.open('spec/fixtures/images/logo.png') }
|
|
7
|
+
|
|
8
|
+
trait :second_image do
|
|
9
|
+
logo { File.open('spec/fixtures/images/logo2.png') }
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe NoCms::Blocks::Block do
|
|
4
|
+
it_behaves_like "model with required attributes", :block, [:layout]
|
|
5
|
+
|
|
6
|
+
context "when blocks have layouts" do
|
|
7
|
+
|
|
8
|
+
context "with simple fields" do
|
|
9
|
+
|
|
10
|
+
before do
|
|
11
|
+
NoCms::Blocks.configure do |config|
|
|
12
|
+
config.block_layouts = {
|
|
13
|
+
'title-long_text' => {
|
|
14
|
+
template: 'title-long_text',
|
|
15
|
+
fields: {
|
|
16
|
+
title: :string,
|
|
17
|
+
body: :text
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
let(:block_with_layout) { NoCms::Blocks::Block.create attributes_for(:block).merge(layout: 'title-long_text', title: block_title) }
|
|
25
|
+
let(:block_title) { Faker::Lorem.sentence }
|
|
26
|
+
|
|
27
|
+
subject { block_with_layout }
|
|
28
|
+
|
|
29
|
+
it("should respond to layout fields") do
|
|
30
|
+
expect{subject.title}.to_not raise_error
|
|
31
|
+
expect{subject.body}.to_not raise_error
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it("should not respond to fields from other layouts") do
|
|
35
|
+
expect{subject.no_title}.to raise_error(NoMethodError)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it("should save info in layout fields") do
|
|
39
|
+
expect(subject.title).to eq block_title
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it("should save nil fields") do
|
|
43
|
+
expect(subject.body).to be_blank
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
context "when updating various fields" do
|
|
47
|
+
|
|
48
|
+
let(:new_block_title) { "new #{Faker::Lorem.sentence}" }
|
|
49
|
+
let(:block_body) { Faker::Lorem.paragraph }
|
|
50
|
+
|
|
51
|
+
before do
|
|
52
|
+
subject.update_attributes title: new_block_title, body: block_body
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it("should save info in layout fields") do
|
|
56
|
+
expect(subject.title).to eq new_block_title
|
|
57
|
+
expect(subject.body).to eq block_body
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context "when updating just one field" do
|
|
63
|
+
|
|
64
|
+
let(:new_block_title) { "new #{Faker::Lorem.sentence}" }
|
|
65
|
+
|
|
66
|
+
before do
|
|
67
|
+
subject.update_attribute :title, new_block_title
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
it("should save info in layout field") do
|
|
71
|
+
expect(subject.title).to eq new_block_title
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
context "with related models" do
|
|
79
|
+
|
|
80
|
+
before do
|
|
81
|
+
NoCms::Blocks.configure do |config|
|
|
82
|
+
config.block_layouts = {
|
|
83
|
+
'logo-caption' => {
|
|
84
|
+
template: 'logo_caption',
|
|
85
|
+
fields: {
|
|
86
|
+
caption: :string,
|
|
87
|
+
logo: TestImage
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
let(:image_attributes) { attributes_for(:test_image) }
|
|
95
|
+
|
|
96
|
+
let(:block_with_layout) { NoCms::Blocks::Block.create attributes_for(:block).merge(
|
|
97
|
+
layout: 'logo-caption',
|
|
98
|
+
caption: Faker::Lorem.sentence,
|
|
99
|
+
logo: image_attributes
|
|
100
|
+
)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
before { subject }
|
|
104
|
+
subject { block_with_layout }
|
|
105
|
+
|
|
106
|
+
it("should respond to layout fields") do
|
|
107
|
+
expect{subject.caption}.to_not raise_error
|
|
108
|
+
expect{subject.logo}.to_not raise_error
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it("should return objects") do
|
|
112
|
+
expect(subject.logo).to be_a(TestImage)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
it("should return objects with the right value") do
|
|
116
|
+
expect(subject.logo.name).to eq image_attributes[:name]
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
it("should save related objects") do
|
|
120
|
+
expect(TestImage.first).to_not be_nil
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
context "when related objects are modified outside" do
|
|
124
|
+
|
|
125
|
+
let(:logo) { TestImage.first }
|
|
126
|
+
let(:new_testing_name) { "new testing name" }
|
|
127
|
+
|
|
128
|
+
before do
|
|
129
|
+
subject
|
|
130
|
+
logo.update_attribute :name, new_testing_name
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
it("should get those modifications") do
|
|
134
|
+
expect(subject.reload.logo.name).to eq new_testing_name
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
it("should not overwrite those modifications") do
|
|
138
|
+
subject.save!
|
|
139
|
+
expect(logo.reload.name).to eq new_testing_name
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
context "when we update the related object" do
|
|
145
|
+
|
|
146
|
+
let(:logo) { TestImage.first }
|
|
147
|
+
let(:new_testing_name) { "new testing name" }
|
|
148
|
+
let(:new_image_attributes) { attributes_for(:test_image,:second_image) }
|
|
149
|
+
|
|
150
|
+
before do
|
|
151
|
+
subject.update_attributes logo: { name: new_testing_name, logo: new_image_attributes[:logo] }
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
it("should be modified in database") do
|
|
155
|
+
expect(logo.name).to eq new_testing_name
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it("should modify uploaded files") do
|
|
159
|
+
expect(logo[:logo]).to eq File.basename(new_image_attributes[:logo].path)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
context "when the related object is not valid" do
|
|
165
|
+
|
|
166
|
+
let(:logo) { TestImage.first }
|
|
167
|
+
let(:new_testing_caption) { "new testing caption" }
|
|
168
|
+
|
|
169
|
+
before do
|
|
170
|
+
subject.update_attributes caption: new_testing_caption, logo: { name: nil }
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
it("should modify the block attribute") do
|
|
174
|
+
expect(subject.reload.caption).to eq new_testing_caption
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it("should not save the invalid objects") do
|
|
178
|
+
expect(subject.logo.reload.name).to_not be_nil
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
context "when blocks are marked as draft" do
|
|
189
|
+
|
|
190
|
+
let(:no_draft_blocks) { create_list :block, 2, draft: false }
|
|
191
|
+
let(:draft_blocks) { create_list :block, 2, draft: true }
|
|
192
|
+
|
|
193
|
+
before { draft_blocks && no_draft_blocks }
|
|
194
|
+
|
|
195
|
+
it("should distinguish between drafts and no drafts") do
|
|
196
|
+
expect(NoCms::Blocks::Block.drafts).to match_array draft_blocks
|
|
197
|
+
expect(NoCms::Blocks::Block.no_drafts).to match_array no_draft_blocks
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe NoCms::Blocks::Block do
|
|
4
|
+
|
|
5
|
+
context "when visiting the home" do
|
|
6
|
+
|
|
7
|
+
let(:image_attributes) { attributes_for(:test_image) }
|
|
8
|
+
let(:block_default_layout) { create :block, layout: 'default', title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph }
|
|
9
|
+
let(:block_3_columns_layout) { create :block, layout: 'title-3_columns', title: Faker::Lorem.sentence, column_1: Faker::Lorem.paragraph, column_2: Faker::Lorem.paragraph, column_3: Faker::Lorem.paragraph }
|
|
10
|
+
let(:block_logo) { create :block, layout: 'logo-caption', caption: Faker::Lorem.sentence, logo: image_attributes }
|
|
11
|
+
let(:block_draft) { create :block, layout: 'default', title: Faker::Lorem.sentence, body: Faker::Lorem.paragraph, draft: true }
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
before do
|
|
15
|
+
NoCms::Blocks.configure do |config|
|
|
16
|
+
config.block_layouts = {
|
|
17
|
+
'default' => {
|
|
18
|
+
template: 'default',
|
|
19
|
+
fields: {
|
|
20
|
+
title: :string,
|
|
21
|
+
body: :text
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
'title-3_columns' => {
|
|
25
|
+
template: 'title_3_columns',
|
|
26
|
+
fields: {
|
|
27
|
+
title: :string,
|
|
28
|
+
column_1: :text,
|
|
29
|
+
column_2: :text,
|
|
30
|
+
column_3: :text
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
'logo-caption' => {
|
|
34
|
+
template: 'logo_caption',
|
|
35
|
+
fields: {
|
|
36
|
+
caption: :string,
|
|
37
|
+
logo: TestImage
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
block_logo
|
|
45
|
+
block_draft
|
|
46
|
+
block_default_layout
|
|
47
|
+
block_3_columns_layout
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
visit '/'
|
|
51
|
+
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
it("should display default layout block") do
|
|
55
|
+
expect(page).to have_selector('.title', text: block_default_layout.title)
|
|
56
|
+
expect(page).to have_selector('.body', text: block_default_layout.body)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it("should display 3 columns layout block") do
|
|
60
|
+
expect(page).to have_selector('h2', text: block_3_columns_layout.title)
|
|
61
|
+
expect(page).to have_selector('.column_1', text: block_3_columns_layout.column_1)
|
|
62
|
+
expect(page).to have_selector('.column_2', text: block_3_columns_layout.column_2)
|
|
63
|
+
expect(page).to have_selector('.column_3', text: block_3_columns_layout.column_3)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it("should display logo layout block") do
|
|
67
|
+
expect(page).to have_selector('.caption', text: block_logo.caption)
|
|
68
|
+
expect(page).to have_selector("img[src='#{block_logo.logo.logo.url}']")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it("should display not draft block") do
|
|
72
|
+
expect(page).to_not have_selector('.title', text: block_draft.title)
|
|
73
|
+
expect(page).to_not have_selector('.body', text: block_draft.body)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "when a cache key is rendered by a block", caching: true do
|
|
77
|
+
|
|
78
|
+
let(:block_logo) { create :block, layout: 'logo-caption', caption: Faker::Lorem.sentence, logo: image_attributes }
|
|
79
|
+
let(:cache_key) { 'supercalifragilisticoespialidoso' }
|
|
80
|
+
|
|
81
|
+
before { block_logo }
|
|
82
|
+
|
|
83
|
+
it("should not cache it") do
|
|
84
|
+
visit '/'
|
|
85
|
+
expect(page).to_not have_text cache_key
|
|
86
|
+
visit "/?cache_key=#{cache_key}"
|
|
87
|
+
expect(page).to have_text cache_key
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
end
|