liquid4-rails5 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +24 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +22 -0
- data/CHANGELOG.md +36 -0
- data/Gemfile +12 -0
- data/Guardfile +33 -0
- data/LICENSE.txt +22 -0
- data/README.md +156 -0
- data/Rakefile +37 -0
- data/gemfiles/rails_32.gemfile +11 -0
- data/gemfiles/rails_40.gemfile +11 -0
- data/gemfiles/rails_41.gemfile +11 -0
- data/gemfiles/rails_42.gemfile +11 -0
- data/lib/liquid-rails/drops/collection_drop.rb +91 -0
- data/lib/liquid-rails/drops/drop.rb +130 -0
- data/lib/liquid-rails/drops/droppable.rb +22 -0
- data/lib/liquid-rails/file_system.rb +16 -0
- data/lib/liquid-rails/filters/asset_tag_filter.rb +23 -0
- data/lib/liquid-rails/filters/asset_url_filter.rb +35 -0
- data/lib/liquid-rails/filters/date_filter.rb +17 -0
- data/lib/liquid-rails/filters/google_static_map_url_filter.rb +30 -0
- data/lib/liquid-rails/filters/misc_filter.rb +29 -0
- data/lib/liquid-rails/filters/number_filter.rb +22 -0
- data/lib/liquid-rails/filters/paginate_filter.rb +59 -0
- data/lib/liquid-rails/filters/sanitize_filter.rb +17 -0
- data/lib/liquid-rails/filters/text_filter.rb +44 -0
- data/lib/liquid-rails/filters/translate_filter.rb +14 -0
- data/lib/liquid-rails/filters/url_filter.rb +24 -0
- data/lib/liquid-rails/liquid_monkey_patch.rb +106 -0
- data/lib/liquid-rails/matchers.rb +5 -0
- data/lib/liquid-rails/railtie.rb +26 -0
- data/lib/liquid-rails/rspec/drop_example_group.rb +38 -0
- data/lib/liquid-rails/rspec/drop_matchers.rb +165 -0
- data/lib/liquid-rails/rspec/filter_example_group.rb +24 -0
- data/lib/liquid-rails/rspec/tag_example_group.rb +24 -0
- data/lib/liquid-rails/rspec/view_controller_context.rb +45 -0
- data/lib/liquid-rails/tags/content_for_tag.rb +77 -0
- data/lib/liquid-rails/tags/csrf_meta_tags.rb +11 -0
- data/lib/liquid-rails/tags/google_analytics_tag.rb +40 -0
- data/lib/liquid-rails/tags/javascript_tag.rb +22 -0
- data/lib/liquid-rails/tags/paginate_tag.rb +118 -0
- data/lib/liquid-rails/template_handler.rb +44 -0
- data/lib/liquid-rails/version.rb +5 -0
- data/lib/liquid-rails.rb +24 -0
- data/liquid-rails.gemspec +26 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -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 +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/foospace/bar_controller.rb +5 -0
- data/spec/dummy/app/controllers/home_controller.rb +28 -0
- data/spec/dummy/app/controllers/pages_controller.rb +16 -0
- data/spec/dummy/app/helpers/application_helper.rb +5 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/foospace/bar/_partial.liquid +1 -0
- data/spec/dummy/app/views/foospace/bar/index_partial.liquid +3 -0
- data/spec/dummy/app/views/home/_html_liquid_partial.liquid +1 -0
- data/spec/dummy/app/views/home/_partial.liquid +1 -0
- data/spec/dummy/app/views/home/erb_with_html_liquid_partial.erb +1 -0
- data/spec/dummy/app/views/home/index.liquid +1 -0
- data/spec/dummy/app/views/home/index_partial.liquid +4 -0
- data/spec/dummy/app/views/home/index_partial_with_full_path.liquid +4 -0
- data/spec/dummy/app/views/home/index_with_filter.liquid +2 -0
- data/spec/dummy/app/views/home/index_with_layout.liquid +1 -0
- data/spec/dummy/app/views/layouts/application.liquid +2 -0
- data/spec/dummy/app/views/pages/index_without_filter.liquid +2 -0
- data/spec/dummy/app/views/shared/_partial.liquid +1 -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/application.rb +25 -0
- data/spec/dummy/config/boot.rb +5 -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 +36 -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/secret_token.rb +17 -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 +5 -0
- data/spec/dummy/config/locales/km.yml +5 -0
- data/spec/dummy/config/routes.rb +14 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -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/fixtures/poro.rb +58 -0
- data/spec/lib/liquid-rails/drops/drop_spec.rb +119 -0
- data/spec/lib/liquid-rails/filters/asset_tag_filter_spec.rb +22 -0
- data/spec/lib/liquid-rails/filters/asset_url_filter_spec.rb +34 -0
- data/spec/lib/liquid-rails/filters/google_static_map_url_filter_spec.rb +23 -0
- data/spec/lib/liquid-rails/filters/misc_filter_spec.rb +26 -0
- data/spec/lib/liquid-rails/filters/translate_filter_spec.rb +29 -0
- data/spec/lib/liquid-rails/railtie_spec.rb +9 -0
- data/spec/lib/liquid-rails/rspec/drop_matchers_spec.rb +34 -0
- data/spec/lib/liquid-rails/tags/content_for_tag_spec.rb +33 -0
- data/spec/lib/liquid-rails/tags/csrf_meta_tag_spec.rb +25 -0
- data/spec/lib/liquid-rails/tags/google_analtyics_tag_spec.rb +28 -0
- data/spec/lib/liquid-rails/tags/javascript_tag_spec.rb +14 -0
- data/spec/lib/liquid-rails/tags/paginate_tag_spec.rb +160 -0
- data/spec/lib/liquid-rails/template_handler_spec.rb +67 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/delegate_matcher.rb +60 -0
- metadata +274 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class AssetTagFilterKlass
|
4
|
+
include Liquid::Rails::AssetTagFilter
|
5
|
+
end
|
6
|
+
|
7
|
+
module Liquid
|
8
|
+
module Rails
|
9
|
+
describe AssetTagFilter do
|
10
|
+
subject { AssetTagFilterKlass.new }
|
11
|
+
|
12
|
+
it { should delegate(:audio_tag).to(:h) }
|
13
|
+
it { should delegate(:auto_discovery_link_tag).to(:h) }
|
14
|
+
it { should delegate(:favicon_link_tag).to(:h) }
|
15
|
+
it { should delegate(:image_alt).to(:h) }
|
16
|
+
it { should delegate(:image_tag).to(:h) }
|
17
|
+
it { should delegate(:javascript_include_tag).to(:h) }
|
18
|
+
it { should delegate(:stylesheet_link_tag).to(:h) }
|
19
|
+
it { should delegate(:video_tag).to(:h) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class AssetUrlFilterKlass
|
4
|
+
include Liquid::Rails::AssetUrlFilter
|
5
|
+
end
|
6
|
+
|
7
|
+
module Liquid
|
8
|
+
module Rails
|
9
|
+
describe AssetUrlFilter do
|
10
|
+
subject { AssetUrlFilterKlass.new }
|
11
|
+
|
12
|
+
it { should delegate(:asset_path).to(:h) }
|
13
|
+
it { should delegate(:asset_url).to(:h) }
|
14
|
+
|
15
|
+
it { should delegate(:audio_path).to(:h) }
|
16
|
+
it { should delegate(:audio_url).to(:h) }
|
17
|
+
|
18
|
+
it { should delegate(:font_path).to(:h) }
|
19
|
+
it { should delegate(:font_url).to(:h) }
|
20
|
+
|
21
|
+
it { should delegate(:image_path).to(:h) }
|
22
|
+
it { should delegate(:image_url).to(:h) }
|
23
|
+
|
24
|
+
it { should delegate(:javascript_path).to(:h) }
|
25
|
+
it { should delegate(:javascript_url).to(:h) }
|
26
|
+
|
27
|
+
it { should delegate(:stylesheet_path).to(:h) }
|
28
|
+
it { should delegate(:stylesheet_url).to(:h) }
|
29
|
+
|
30
|
+
it { should delegate(:video_path).to(:h) }
|
31
|
+
it { should delegate(:video_url).to(:h) }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Liquid
|
4
|
+
module Rails
|
5
|
+
describe GoogleStaticMapUrlFilter, type: :filter do
|
6
|
+
it 'returns url with center' do
|
7
|
+
expect_template_result("{{ '600x300' | google_static_map_url: center: '40.714728,-73.998672' }}", 'https://maps.googleapis.com/maps/api/staticmap?center=40.714728%2C-73.998672&size=600x300')
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns url with zoom' do
|
11
|
+
expect_template_result("{{ '600x300' | google_static_map_url: zoom: 13 }}", 'https://maps.googleapis.com/maps/api/staticmap?size=600x300&zoom=13')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns url with maptype' do
|
15
|
+
expect_template_result("{{ '600x300' | google_static_map_url: maptype: 'hybrid' }}", 'https://maps.googleapis.com/maps/api/staticmap?maptype=hybrid&size=600x300')
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'returns url with markers' do
|
19
|
+
expect_template_result("{{ '600x300' | google_static_map_url: markers: 'color:blue|label:S|40.702147,-74.015794;color:green|label:G|40.711614,-74.012318' }}", 'https://maps.googleapis.com/maps/api/staticmap?size=600x300&markers=color%3Ablue%7Clabel%3AS%7C40.702147%2C-74.015794&markers=color%3Agreen%7Clabel%3AG%7C40.711614%2C-74.012318')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Liquid
|
4
|
+
module Rails
|
5
|
+
describe MiscFilter do
|
6
|
+
let(:context) { ::Liquid::Context.new }
|
7
|
+
|
8
|
+
context '#index' do
|
9
|
+
it 'returns value at the specified index' do
|
10
|
+
context['array'] = [1, 2, 3]
|
11
|
+
expect(::Liquid::Variable.new("array | index: 0").render(context)).to eq(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns nil when outside range' do
|
15
|
+
context['array'] = [1, 2, 3]
|
16
|
+
expect(::Liquid::Variable.new("array | index: 5").render(context)).to eq(nil)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it '#jsonify' do
|
21
|
+
context['listing'] = { name: 'Listing A' }
|
22
|
+
expect(::Liquid::Variable.new("listing | jsonify").render(context)).to eq(%|{"name":"Listing A"}|)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Liquid
|
4
|
+
module Rails
|
5
|
+
describe TranslateFilter do
|
6
|
+
let(:context) { ::Liquid::Context.new }
|
7
|
+
|
8
|
+
before do
|
9
|
+
context.registers[:view] = ActionView::Base.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'translate with default locale' do
|
13
|
+
expect(::Liquid::Variable.new("'welcome' | translate").render(context)).to eq('Welcome everyone!')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'translate with specified locale' do
|
17
|
+
expect(::Liquid::Variable.new("'welcome' | translate: locale: 'km'").render(context)).to eq('សូមស្វាគមន៍')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'translate with scope' do
|
21
|
+
expect(::Liquid::Variable.new("'home' | translate: locale: 'km', scope: 'links'").render(context)).to eq('ទំព័រដើម')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'translate with interpolation' do
|
25
|
+
expect(::Liquid::Variable.new("'welcome_name' | translate: locale: 'en', name: 'Jeremy'").render(context)).to eq('Welcome, Jeremy')
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ProfileDrop, type: :drop do
|
4
|
+
include Liquid::Rails::Rspec::DropMatchers
|
5
|
+
|
6
|
+
it { should have_attribute(:name) }
|
7
|
+
it { should have_attribute(:description) }
|
8
|
+
it { should_not have_attribute(:not_found) }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe PostDrop, type: :drop do
|
12
|
+
include Liquid::Rails::Rspec::DropMatchers
|
13
|
+
|
14
|
+
it { should have_many(:comments) }
|
15
|
+
it { should_not have_many(:not_found) }
|
16
|
+
|
17
|
+
it { should have_many(:recomments).class_name('CommentsDrop') }
|
18
|
+
it { should have_many(:recomments).with('ReCommentDrop') }
|
19
|
+
it { should have_many(:recomments).class_name('CommentsDrop').with('ReCommentDrop') }
|
20
|
+
|
21
|
+
it { should_not have_many(:recomments).class_name('NotFound') }
|
22
|
+
it { should_not have_many(:recomments).with('NotFound') }
|
23
|
+
it { should_not have_many(:recomments).class_name('NotFound').with('NotFound') }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe CommentDrop, type: :drop do
|
27
|
+
include Liquid::Rails::Rspec::DropMatchers
|
28
|
+
|
29
|
+
it { should belongs_to(:post) }
|
30
|
+
it { should_not belongs_to(:not_found) }
|
31
|
+
|
32
|
+
it { should belongs_to(:repost).class_name('RePostDrop') }
|
33
|
+
it { should_not belongs_to(:repost).class_name('NotFound') }
|
34
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Liquid
|
4
|
+
module Rails
|
5
|
+
describe ContentForTag, type: :tag do
|
6
|
+
it 'content_for and yield with non-quoted key' do
|
7
|
+
Liquid::Template.parse(%|{% content_for not_authorized0 %}alert('You are not authorized to do that!');{% endcontent_for %}|).render(context)
|
8
|
+
|
9
|
+
expect_template_result(%|{% yield not_authorized0 %}|, "alert('You are not authorized to do that!');")
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'content_for and yield with quoted key' do
|
13
|
+
Liquid::Template.parse(%|{% content_for 'not_authorized1' %}alert('You are not authorized to do that!');{% endcontent_for %}|).render(context)
|
14
|
+
|
15
|
+
expect_template_result(%|{% yield 'not_authorized1' %}|, "alert('You are not authorized to do that!');")
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'invokes content_for with the same identifier multiple times' do
|
19
|
+
Liquid::Template.parse(%|{% content_for 'not_authorized2' %}alert('You are not authorized to do that 1!');{% endcontent_for %}|).render(context)
|
20
|
+
Liquid::Template.parse(%|{% content_for 'not_authorized2' %}alert('You are not authorized to do that 2!');{% endcontent_for %}|).render(context)
|
21
|
+
|
22
|
+
expect_template_result(%|{% yield 'not_authorized2' %}|, "alert('You are not authorized to do that 1!');alert('You are not authorized to do that 2!');")
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'invokes content_for with the same identifier multiple times and flush' do
|
26
|
+
Liquid::Template.parse(%|{% content_for 'not_authorized3' %}alert('You are not authorized to do that 1!');{% endcontent_for %}|).render(context)
|
27
|
+
Liquid::Template.parse(%|{% content_for 'not_authorized3' flush true %}alert('You are not authorized to do that 2!');{% endcontent_for %}|).render(context)
|
28
|
+
|
29
|
+
expect_template_result(%|{% yield 'not_authorized3' %}|, "alert('You are not authorized to do that 2!');")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Liquid
|
4
|
+
module Rails
|
5
|
+
describe CsrfMetaTags, type: :tag do
|
6
|
+
let(:context) { ::Liquid::Context.new({}, {}, { view: view }) }
|
7
|
+
|
8
|
+
it '#crsf_meta_tags' do
|
9
|
+
allow(view).to receive(:protect_against_forgery?).and_return(true)
|
10
|
+
allow(view).to receive(:form_authenticity_token).and_return('rails_form_authenticity_token')
|
11
|
+
|
12
|
+
result = Liquid::Template.parse('{% csrf_meta_tags %}').render(context)
|
13
|
+
metas = result.split("\n").map { |item| Nokogiri::XML(item).children.first }
|
14
|
+
expect(metas.length).to eq(2)
|
15
|
+
expect(metas[0].name).to eq('meta')
|
16
|
+
expect(metas[0]['name']).to eq('csrf-param')
|
17
|
+
expect(metas[0]['content']).to eq('authenticity_token')
|
18
|
+
|
19
|
+
expect(metas[1].name).to eq('meta')
|
20
|
+
expect(metas[1]['name']).to eq('csrf-token')
|
21
|
+
expect(metas[1]['content']).to eq('rails_form_authenticity_token')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Liquid
|
4
|
+
module Rails
|
5
|
+
describe GoogleAnalyticsTag, type: :tag do
|
6
|
+
let(:context) { ::Liquid::Context.new({}, {}, { view: view }) }
|
7
|
+
|
8
|
+
it '#google_analytics' do
|
9
|
+
result = Liquid::Template.parse("{% google_analytics_tag 'UA-XXXXX-X' %}").render(context)
|
10
|
+
|
11
|
+
expect(result).to eq(
|
12
|
+
%{
|
13
|
+
<script type="text/javascript">
|
14
|
+
|
15
|
+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
16
|
+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
17
|
+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
18
|
+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
19
|
+
ga('create', 'UA-XXXXX-X', 'auto');
|
20
|
+
ga('send', 'pageview');
|
21
|
+
|
22
|
+
</script>
|
23
|
+
}
|
24
|
+
)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Liquid
|
4
|
+
module Rails
|
5
|
+
describe JavascriptTag, type: :tag do
|
6
|
+
let(:context) { ::Liquid::Context.new({}, {}, { view: view }) }
|
7
|
+
|
8
|
+
it '#crsf_meta_tags' do
|
9
|
+
result = Liquid::Template.parse("{% javascript_tag %} alert('Hello Liquid-Rails!') {% endjavascript_tag %}").render(context)
|
10
|
+
expect(result).to eq(%|<script type=\"text/javascript\">\n//<![CDATA[\n alert('Hello Liquid-Rails!') \n//]]>\n</script>|)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Liquid
|
4
|
+
module Rails
|
5
|
+
describe PaginateTag, type: :tag do
|
6
|
+
before(:all) do
|
7
|
+
post = ::Post.new(title: 'New Post', body: 'Body')
|
8
|
+
comment1 = ::Comment.new(id: 1, body: 'COMMENT 1')
|
9
|
+
comment2 = ::Comment.new(id: 2, body: 'COMMENT 2')
|
10
|
+
comment3 = ::Comment.new(id: 3, body: 'COMMENT 3')
|
11
|
+
comment4 = ::Comment.new(id: 4, body: 'COMMENT 4')
|
12
|
+
comment5 = ::Comment.new(id: 5, body: 'COMMENT 5')
|
13
|
+
post.comments = [comment1, comment2, comment3, comment4, comment5]
|
14
|
+
@post_drop = ::PostDrop.new(post)
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'first_page' do
|
18
|
+
it 'returns the page size' do
|
19
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.collection | size }}{% endpaginate %}", '2', { 'post' => @post_drop })
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'returns the comments inside the collection' do
|
23
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.collection[0].body }},{{ paginate.collection[1].body }}{% endpaginate %}", 'COMMENT 1,COMMENT 2', { 'post' => @post_drop })
|
24
|
+
end
|
25
|
+
|
26
|
+
it '#current_offset' do
|
27
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_offset }}{% endpaginate %}", '0', { 'post' => @post_drop })
|
28
|
+
end
|
29
|
+
|
30
|
+
it '#current_page' do
|
31
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_page }}{% endpaginate %}", '1', { 'post' => @post_drop })
|
32
|
+
end
|
33
|
+
|
34
|
+
it '#page_size' do
|
35
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.page_size }}{% endpaginate %}", '2', { 'post' => @post_drop })
|
36
|
+
end
|
37
|
+
|
38
|
+
it '#pages' do
|
39
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.pages }}{% endpaginate %}", '3', { 'post' => @post_drop })
|
40
|
+
end
|
41
|
+
|
42
|
+
it '#items' do
|
43
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.items }}{% endpaginate %}", '5', { 'post' => @post_drop })
|
44
|
+
end
|
45
|
+
|
46
|
+
it '#previous' do
|
47
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.previous }}{% endpaginate %}", '', { 'post' => @post_drop })
|
48
|
+
end
|
49
|
+
|
50
|
+
it '#next' do
|
51
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.next }}{% endpaginate %}", %|{"title"=>"Next »", "url"=>"/?page=2", "is_link"=>true}|, { 'post' => @post_drop })
|
52
|
+
end
|
53
|
+
|
54
|
+
it '#parts' do
|
55
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.parts }}{% endpaginate %}", %|{"title"=>1, "is_link"=>false, "hellip_break"=>false}{"title"=>2, "url"=>"/?page=2", "is_link"=>true}{"title"=>3, "url"=>"/?page=3", "is_link"=>true}|, { 'post' => @post_drop })
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'second_page' do
|
60
|
+
before(:all) { controller.params[:page] = 2 }
|
61
|
+
after(:all) { controller.params[:page] = nil }
|
62
|
+
|
63
|
+
it '#current_page' do
|
64
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_page }}{% endpaginate %}", '2', { 'post' => @post_drop })
|
65
|
+
end
|
66
|
+
|
67
|
+
it '#previous' do
|
68
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.previous }}{% endpaginate %}", %|{"title"=>"« Previous", "url"=>"/?page=1", "is_link"=>true}|, { 'post' => @post_drop })
|
69
|
+
end
|
70
|
+
|
71
|
+
it '#next' do
|
72
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.next }}{% endpaginate %}", %|{"title"=>"Next »", "url"=>"/?page=3", "is_link"=>true}|, { 'post' => @post_drop })
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'last_page' do
|
77
|
+
before(:all) { controller.params[:page] = 3 }
|
78
|
+
after(:all) { controller.params[:page] = nil }
|
79
|
+
|
80
|
+
it 'returns the page size' do
|
81
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.collection | size }}{% endpaginate %}", '1', { 'post' => @post_drop })
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns the comments inside the collection' do
|
85
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.collection[0].body }}{% endpaginate %}", 'COMMENT 5', { 'post' => @post_drop })
|
86
|
+
end
|
87
|
+
|
88
|
+
it '#current_offset' do
|
89
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_offset }}{% endpaginate %}", '4', { 'post' => @post_drop })
|
90
|
+
end
|
91
|
+
|
92
|
+
it '#current_page' do
|
93
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_page }}{% endpaginate %}", '3', { 'post' => @post_drop })
|
94
|
+
end
|
95
|
+
|
96
|
+
it '#page_size' do
|
97
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.page_size }}{% endpaginate %}", '2', { 'post' => @post_drop })
|
98
|
+
end
|
99
|
+
|
100
|
+
it '#pages' do
|
101
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.pages }}{% endpaginate %}", '3', { 'post' => @post_drop })
|
102
|
+
end
|
103
|
+
|
104
|
+
it '#items' do
|
105
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.items }}{% endpaginate %}", '5', { 'post' => @post_drop })
|
106
|
+
end
|
107
|
+
|
108
|
+
it '#previous' do
|
109
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.previous }}{% endpaginate %}", %|{"title"=>"« Previous", "url"=>"/?page=2", "is_link"=>true}|, { 'post' => @post_drop })
|
110
|
+
end
|
111
|
+
|
112
|
+
it '#next' do
|
113
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.next }}{% endpaginate %}", %||, { 'post' => @post_drop })
|
114
|
+
end
|
115
|
+
|
116
|
+
it '#parts' do
|
117
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate.parts }}{% endpaginate %}", %|{"title"=>1, "url"=>"/?page=1", "is_link"=>true}{"title"=>2, "url"=>"/?page=2", "is_link"=>true}{"title"=>3, "is_link"=>false, "hellip_break"=>false}|, { 'post' => @post_drop })
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
context 'default_pagination' do
|
122
|
+
after(:all) { controller.params[:page] = nil }
|
123
|
+
|
124
|
+
it 'is in the first_page' do
|
125
|
+
controller.params[:page] = 1
|
126
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate | default_pagination }}{% endpaginate %}", %|<span class=\"page current\">1</span> <span class=\"page\"><a href=\"/?page=2\">2</a></span> <span class=\"page\"><a href=\"/?page=3\">3</a></span> <span class=\"next\"><a href=\"/?page=2\" rel=\"next\">Next »</a></span>|, { 'post' => @post_drop })
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'is in the second_page' do
|
130
|
+
controller.params[:page] = 2
|
131
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate | default_pagination }}{% endpaginate %}", %|<span class=\"prev\"><a href=\"/?page=1\" rel=\"prev\">« Previous</a></span> <span class=\"page\"><a href=\"/?page=1\">1</a></span> <span class=\"page current\">2</span> <span class=\"page\"><a href=\"/?page=3\">3</a></span> <span class=\"next\"><a href=\"/?page=3\" rel=\"next\">Next »</a></span>|, { 'post' => @post_drop })
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'is in the last_page' do
|
135
|
+
controller.params[:page] = 3
|
136
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate | default_pagination }}{% endpaginate %}", %|<span class=\"prev\"><a href=\"/?page=2\" rel=\"prev\">« Previous</a></span> <span class=\"page\"><a href=\"/?page=1\">1</a></span> <span class=\"page\"><a href=\"/?page=2\">2</a></span> <span class=\"page current\">3</span>|, { 'post' => @post_drop })
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context 'bootstrap_pagination' do
|
141
|
+
after(:all) { controller.params[:page] = nil }
|
142
|
+
|
143
|
+
it 'is in the first_page' do
|
144
|
+
controller.params[:page] = 1
|
145
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate | bootstrap_pagination }}{% endpaginate %}", %|<nav><ul class="pagination "> <li class="disabled"><a href="#" aria-label="Previous"><span aria-hidden="true">« Previous</span></a></li> <li class="active"><span>1</span></li> <li><a href="/?page=2">2</a></li> <li><a href="/?page=3">3</a></li> <li><a href="/?page=2" aria-label="Next"><span aria-hidden="true">Next »</span></a></li> </ul></nav>|, { 'post' => @post_drop })
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'is in the second_page' do
|
149
|
+
controller.params[:page] = 2
|
150
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate | bootstrap_pagination }}{% endpaginate %}", %|<nav><ul class="pagination "> <li><a href="/?page=1" aria-label="Previous"><span aria-hidden="true">« Previous</span></a></li> <li><a href="/?page=1">1</a></li> <li class="active"><span>2</span></li> <li><a href="/?page=3">3</a></li> <li><a href="/?page=3" aria-label="Next"><span aria-hidden="true">Next »</span></a></li> </ul></nav>|, { 'post' => @post_drop })
|
151
|
+
end
|
152
|
+
|
153
|
+
it 'is in the last_page' do
|
154
|
+
controller.params[:page] = 3
|
155
|
+
expect_template_result("{% paginate post.comments by 2 %}{{ paginate | bootstrap_pagination }}{% endpaginate %}", %|<nav><ul class="pagination "> <li><a href="/?page=2" aria-label="Previous"><span aria-hidden="true">« Previous</span></a></li> <li><a href="/?page=1">1</a></li> <li><a href="/?page=2">2</a></li> <li class="active"><span>3</span></li> <li class="disabled"><a href="#" aria-label="Next"><span aria-hidden="true">Next »</span></a></li> </ul></nav>|, { 'post' => @post_drop })
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Request', type: :feature do
|
4
|
+
context 'render without layout' do
|
5
|
+
it 'renders with liquid template' do
|
6
|
+
visit '/'
|
7
|
+
|
8
|
+
expect(page.body).to eq('Liquid on Rails')
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'sets content_type as html by default' do
|
12
|
+
visit '/'
|
13
|
+
|
14
|
+
expect(page.response_headers['Content-Type']).to eq('text/html; charset=utf-8')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'render with layout' do
|
19
|
+
it 'renders with layout' do
|
20
|
+
visit '/index_with_layout'
|
21
|
+
|
22
|
+
expect(page.body).to eq("Application Layout\nLiquid on Rails")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'render with partial' do
|
27
|
+
it 'no full path for the current controller' do
|
28
|
+
visit '/index_partial'
|
29
|
+
|
30
|
+
expect(page.body).to eq("Application Layout\nLiquid on Rails\n\nHome Partial\nShared Partial")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'full path' do
|
34
|
+
visit '/index_partial_with_full_path'
|
35
|
+
|
36
|
+
expect(page.body).to eq("Application Layout\nLiquid on Rails\n\nHome Partial\nShared Partial")
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'respects namespace of original template for partials path' do
|
40
|
+
visit '/foospace/bar/index_partial'
|
41
|
+
|
42
|
+
expect(page.body.strip).to eq("Foospace::BarController\n\nBar Partial")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'render with filter' do
|
47
|
+
it 'renders with helper' do
|
48
|
+
visit '/index_with_filter'
|
49
|
+
|
50
|
+
expect(page.body).to eq("Application Layout\nLiquid on Rails\nThis...")
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'renders with helper' do
|
54
|
+
visit '/index_without_filter'
|
55
|
+
|
56
|
+
expect(page.body).to eq("Application Layout\nLiquid on Rails\nThis is a long section of text")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'render html within an erb template' do
|
61
|
+
it 'does not escape the html' do
|
62
|
+
visit '/erb_with_html_liquid_partial'
|
63
|
+
|
64
|
+
expect(page.body.strip).to eq("Application Layout\n<p>Partial Content</p>")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
if ENV['CI'] || ENV['COVERAGE']
|
2
|
+
require 'coveralls'
|
3
|
+
require 'simplecov'
|
4
|
+
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter
|
8
|
+
]
|
9
|
+
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter 'drop_example_group.rb'
|
12
|
+
add_filter 'tag_example_group.rb'
|
13
|
+
add_filter 'spec'
|
14
|
+
add_filter 'gemfiles'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Configure Rails Environment
|
19
|
+
ENV['RAILS_ENV'] = 'test'
|
20
|
+
|
21
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
22
|
+
require 'pry'
|
23
|
+
require 'liquid-rails'
|
24
|
+
require 'rspec/rails'
|
25
|
+
require 'capybara/rspec'
|
26
|
+
require 'liquid-rails/matchers'
|
27
|
+
|
28
|
+
Liquid::Template.error_mode = :strict
|
29
|
+
|
30
|
+
Rails.backtrace_cleaner.remove_silencers!
|
31
|
+
|
32
|
+
# Load support files
|
33
|
+
require 'fixtures/poro'
|
34
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
35
|
+
|
36
|
+
RSpec.configure do |config|
|
37
|
+
config.filter_run focus: true
|
38
|
+
config.run_all_when_everything_filtered = true
|
39
|
+
config.include Capybara::RSpecMatchers
|
40
|
+
config.include ActiveSupport::Testing::SetupAndTeardown
|
41
|
+
config.include ActionController::TestCase::Behavior
|
42
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# RSpec matcher to spec delegations.
|
2
|
+
# Gist Version https://gist.github.com/joeytheman/0fe021821e4c62f552ce
|
3
|
+
#
|
4
|
+
#
|
5
|
+
# Usage:
|
6
|
+
#
|
7
|
+
# describe Post do
|
8
|
+
# it { should delegate(:name).to(:author).with_prefix } # post.author_name
|
9
|
+
# it { should delegate(:name).to(:author).with_prefix(:any) } # post.any_name
|
10
|
+
# it { should delegate(:month).to(:created_at) }
|
11
|
+
# it { should delegate(:year).to(:created_at) }
|
12
|
+
# it { should delegate(:something).to(:'@instance_var') }
|
13
|
+
# end
|
14
|
+
|
15
|
+
RSpec::Matchers.define :delegate do |method|
|
16
|
+
match do |delegator|
|
17
|
+
@method = @prefix ? :"#{@prefix}_#{method}" : method
|
18
|
+
@delegator = delegator
|
19
|
+
|
20
|
+
if @to.to_s[0] == '@'
|
21
|
+
# Delegation to an instance variable
|
22
|
+
old_value = @delegator.instance_variable_get(@to)
|
23
|
+
begin
|
24
|
+
@delegator.instance_variable_set(@to, receiver_double(method))
|
25
|
+
@delegator.send(@method) == :called
|
26
|
+
ensure
|
27
|
+
@delegator.instance_variable_set(@to, old_value)
|
28
|
+
end
|
29
|
+
elsif @delegator.respond_to?(@to, true)
|
30
|
+
unless [0,-1].include?(@delegator.method(@to).arity)
|
31
|
+
raise "#{@delegator}'s' #{@to} method does not have zero or -1 arity (it expects parameters)"
|
32
|
+
end
|
33
|
+
allow(@delegator).to receive(@to).and_return(receiver_double(method))
|
34
|
+
@delegator.send(@method) == :called
|
35
|
+
else
|
36
|
+
raise "#{@delegator} does not respond to #{@to}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
description do
|
41
|
+
"delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
|
42
|
+
end
|
43
|
+
|
44
|
+
failure_message do |text|
|
45
|
+
"expected #{@delegator} to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
|
46
|
+
end
|
47
|
+
|
48
|
+
failure_message_when_negated do |text|
|
49
|
+
"expected #{@delegator} not to delegate :#{@method} to its #{@to}#{@prefix ? ' with prefix' : ''}"
|
50
|
+
end
|
51
|
+
|
52
|
+
chain(:to) { |receiver| @to = receiver }
|
53
|
+
chain(:with_prefix) { |*prefix| @prefix = prefix.first || @to }
|
54
|
+
|
55
|
+
def receiver_double(method)
|
56
|
+
double('receiver').tap do |receiver|
|
57
|
+
allow(receiver).to receive(method).and_return(:called)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|