liquid-rails 0.1.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 (110) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +24 -0
  4. data/.rspec +1 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/.travis.yml +17 -0
  8. data/Gemfile +12 -0
  9. data/Guardfile +33 -0
  10. data/LICENSE.txt +22 -0
  11. data/README.md +140 -0
  12. data/Rakefile +27 -0
  13. data/gemfiles/rails_32.gemfile +11 -0
  14. data/gemfiles/rails_40.gemfile +11 -0
  15. data/gemfiles/rails_41.gemfile +11 -0
  16. data/lib/liquid-rails.rb +23 -0
  17. data/lib/liquid-rails/drops/collection_drop.rb +91 -0
  18. data/lib/liquid-rails/drops/drop.rb +114 -0
  19. data/lib/liquid-rails/drops/droppable.rb +22 -0
  20. data/lib/liquid-rails/file_system.rb +14 -0
  21. data/lib/liquid-rails/filters/asset_tag_filter.rb +25 -0
  22. data/lib/liquid-rails/filters/asset_url_filter.rb +37 -0
  23. data/lib/liquid-rails/filters/date_filter.rb +19 -0
  24. data/lib/liquid-rails/filters/google_static_map_url_filter.rb +30 -0
  25. data/lib/liquid-rails/filters/misc_filter.rb +47 -0
  26. data/lib/liquid-rails/filters/number_filter.rb +24 -0
  27. data/lib/liquid-rails/filters/sanitize_filter.rb +19 -0
  28. data/lib/liquid-rails/filters/text_filter.rb +47 -0
  29. data/lib/liquid-rails/filters/translate_filter.rb +13 -0
  30. data/lib/liquid-rails/filters/url_filter.rb +24 -0
  31. data/lib/liquid-rails/matchers.rb +5 -0
  32. data/lib/liquid-rails/railtie.rb +26 -0
  33. data/lib/liquid-rails/rspec/drop_example_group.rb +38 -0
  34. data/lib/liquid-rails/rspec/drop_matchers.rb +159 -0
  35. data/lib/liquid-rails/rspec/filter_example_group.rb +24 -0
  36. data/lib/liquid-rails/rspec/tag_example_group.rb +24 -0
  37. data/lib/liquid-rails/rspec/view_controller_context.rb +44 -0
  38. data/lib/liquid-rails/tags/content_for_tag.rb +68 -0
  39. data/lib/liquid-rails/tags/csrf_meta_tags.rb +11 -0
  40. data/lib/liquid-rails/tags/google_analytics_tag.rb +43 -0
  41. data/lib/liquid-rails/tags/javascript_tag.rb +22 -0
  42. data/lib/liquid-rails/tags/paginate_tag.rb +117 -0
  43. data/lib/liquid-rails/template_handler.rb +44 -0
  44. data/lib/liquid-rails/version.rb +5 -0
  45. data/liquid-rails.gemspec +26 -0
  46. data/spec/dummy/README.rdoc +28 -0
  47. data/spec/dummy/Rakefile +6 -0
  48. data/spec/dummy/app/assets/images/.keep +0 -0
  49. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  50. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  51. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  52. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  53. data/spec/dummy/app/controllers/home_controller.rb +25 -0
  54. data/spec/dummy/app/controllers/pages_controller.rb +16 -0
  55. data/spec/dummy/app/helpers/application_helper.rb +5 -0
  56. data/spec/dummy/app/mailers/.keep +0 -0
  57. data/spec/dummy/app/models/.keep +0 -0
  58. data/spec/dummy/app/models/concerns/.keep +0 -0
  59. data/spec/dummy/app/views/home/_partial.liquid +1 -0
  60. data/spec/dummy/app/views/home/index.liquid +1 -0
  61. data/spec/dummy/app/views/home/index_partial.liquid +4 -0
  62. data/spec/dummy/app/views/home/index_partial_with_full_path.liquid +4 -0
  63. data/spec/dummy/app/views/home/index_with_filter.liquid +2 -0
  64. data/spec/dummy/app/views/home/index_with_layout.liquid +1 -0
  65. data/spec/dummy/app/views/layouts/application.liquid +2 -0
  66. data/spec/dummy/app/views/pages/index_without_filter.liquid +2 -0
  67. data/spec/dummy/app/views/shared/_partial.liquid +1 -0
  68. data/spec/dummy/bin/bundle +3 -0
  69. data/spec/dummy/bin/rails +4 -0
  70. data/spec/dummy/bin/rake +4 -0
  71. data/spec/dummy/config.ru +4 -0
  72. data/spec/dummy/config/application.rb +25 -0
  73. data/spec/dummy/config/boot.rb +5 -0
  74. data/spec/dummy/config/environment.rb +5 -0
  75. data/spec/dummy/config/environments/development.rb +29 -0
  76. data/spec/dummy/config/environments/production.rb +80 -0
  77. data/spec/dummy/config/environments/test.rb +36 -0
  78. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  79. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  80. data/spec/dummy/config/initializers/inflections.rb +16 -0
  81. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  82. data/spec/dummy/config/initializers/secret_token.rb +17 -0
  83. data/spec/dummy/config/initializers/session_store.rb +3 -0
  84. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  85. data/spec/dummy/config/locales/en.yml +4 -0
  86. data/spec/dummy/config/locales/km.yml +4 -0
  87. data/spec/dummy/config/routes.rb +10 -0
  88. data/spec/dummy/lib/assets/.keep +0 -0
  89. data/spec/dummy/public/404.html +58 -0
  90. data/spec/dummy/public/422.html +58 -0
  91. data/spec/dummy/public/500.html +57 -0
  92. data/spec/dummy/public/favicon.ico +0 -0
  93. data/spec/fixtures/poro.rb +58 -0
  94. data/spec/lib/liquid-rails/drops/drop_spec.rb +119 -0
  95. data/spec/lib/liquid-rails/filters/asset_tag_filter_spec.rb +22 -0
  96. data/spec/lib/liquid-rails/filters/asset_url_filter_spec.rb +34 -0
  97. data/spec/lib/liquid-rails/filters/google_static_map_url_filter_spec.rb +23 -0
  98. data/spec/lib/liquid-rails/filters/misc_filter_spec.rb +26 -0
  99. data/spec/lib/liquid-rails/filters/translate_filter_spec.rb +25 -0
  100. data/spec/lib/liquid-rails/railtie_spec.rb +9 -0
  101. data/spec/lib/liquid-rails/rspec/drop_matchers_spec.rb +34 -0
  102. data/spec/lib/liquid-rails/tags/content_for_tag_spec.rb +27 -0
  103. data/spec/lib/liquid-rails/tags/csrf_meta_tag_spec.rb +16 -0
  104. data/spec/lib/liquid-rails/tags/google_analtyics_tag_spec.rb +31 -0
  105. data/spec/lib/liquid-rails/tags/javascript_tag_spec.rb +14 -0
  106. data/spec/lib/liquid-rails/tags/paginate_tag_spec.rb +96 -0
  107. data/spec/lib/liquid-rails/template_handler_spec.rb +53 -0
  108. data/spec/spec_helper.rb +44 -0
  109. data/spec/support/delegate_matcher.rb +60 -0
  110. metadata +261 -0
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ module Liquid
4
+ module Rails
5
+ describe Drop do
6
+ let(:model) { ::Model.new }
7
+ let(:profile) { Profile.new(name: 'Name 1', description: 'Description 1', comments: 'Comments 1') }
8
+ let(:profile_drop) { ProfileDrop.new(profile) }
9
+
10
+ context 'attributes' do
11
+ it '_attributes' do
12
+ expect(profile_drop.class._attributes).to eq([:name, :description])
13
+ end
14
+
15
+ it '#name and #description' do
16
+ expect(profile_drop.name).to eq('Name 1')
17
+ expect(profile_drop.description).to eq('Description 1')
18
+ end
19
+
20
+ it '#before_method' do
21
+ expect(profile_drop.before_method(:name)).to eq(profile_drop.name)
22
+ expect(profile_drop.before_method(:description)).to eq(profile_drop.description)
23
+ end
24
+ end
25
+
26
+ context '#dropify' do
27
+ context 'single' do
28
+ it "instantitates with its inferred drop class" do
29
+ drop = Liquid::Rails::Drop.dropify(profile)
30
+
31
+ expect(drop).to be_instance_of(ProfileDrop)
32
+ end
33
+
34
+ it "instantitates with `Liquid::Rails::Drop` when its inferred drop class doesn't exist" do
35
+ drop = Liquid::Rails::Drop.dropify(Model.new)
36
+
37
+ expect(drop).to be_instance_of(Liquid::Rails::Drop)
38
+ end
39
+
40
+ it "instantitates with the caller drop class" do
41
+ drop = ReProfileDrop.dropify(profile)
42
+ expect(drop).to be_instance_of(ReProfileDrop)
43
+
44
+ drop = ProfileDrop.dropify(profile)
45
+ expect(drop).to be_instance_of(ProfileDrop)
46
+ end
47
+ end
48
+
49
+ context 'array' do
50
+ it "instantitates with collection drop class" do
51
+ array = [1, 2, 3]
52
+
53
+ expect(Liquid::Rails::Drop.dropify(array)).to be_instance_of(Liquid::Rails::CollectionDrop)
54
+ end
55
+ end
56
+ end
57
+
58
+ context 'association' do
59
+ before(:each) do
60
+ @post = ::Post.new({ title: 'New Post', body: 'Body' })
61
+ @comment = ::Comment.new({ id: 1, body: 'ZOMG A COMMENT' })
62
+ @post.comments = [@comment]
63
+ @comment.post = @post
64
+
65
+ @post.recomments= [@comment]
66
+ @comment.repost = @post
67
+
68
+ @post_drop = ::PostDrop.new(@post)
69
+ @comment_drop = ::CommentDrop.new(@comment)
70
+ end
71
+
72
+ context 'has_many' do
73
+ it '#has_many :comments' do
74
+ expect(@post_drop.class._associations[:comments]).to eq({:type=>:has_many, :options=>{}})
75
+ end
76
+
77
+ it '#comments returns as CollectionDrop object' do
78
+ expect(@post_drop.comments).to be_instance_of(Liquid::Rails::CollectionDrop)
79
+ end
80
+
81
+ it '#recomments returns as CommentsDrop object' do
82
+ expect(@post_drop.recomments).to be_instance_of(::CommentsDrop)
83
+ end
84
+
85
+ it '#recomments returns as ReCommentDrop object' do
86
+ expect(@post_drop.recomments[0]).to be_instance_of(::ReCommentDrop)
87
+ end
88
+ end
89
+
90
+ context 'belongs_to' do
91
+ it '#belongs_to' do
92
+ expect(@comment_drop.class._associations[:post]).to eq({:type=>:belongs_to, :options=>{}})
93
+ end
94
+
95
+ it '#post returns as PostDrop object' do
96
+ expect(@comment_drop.post).to be_instance_of(::PostDrop)
97
+ end
98
+
99
+ it '#repost returns as PostDrop object' do
100
+ expect(@comment_drop.repost).to be_instance_of(::RePostDrop)
101
+ end
102
+
103
+ it 'returns nil when the source object is nil' do
104
+ @comment.post = nil
105
+ @comment_drop = ::CommentDrop.new(@comment)
106
+
107
+ expect(@comment_drop.post).to be_nil
108
+ end
109
+ end
110
+
111
+ context '#to_json' do
112
+ it 'returns hash of attributes' do
113
+ expect(profile_drop.to_json).to eq(%|{"name":"Name 1","description":"Description 1"}|)
114
+ end
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
@@ -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,25 @@
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: 'km'").render(context)).to eq('សូមស្វាគមន៍')
18
+ end
19
+
20
+ it 'translate with scope' do
21
+ expect(::Liquid::Variable.new("'home' | translate: 'km', 'links'").render(context)).to eq('ទំព័រដើម')
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ require 'spec_helper'
2
+
3
+ describe Liquid::Rails::Railtie do
4
+ context 'template_engine :liquid' do
5
+ it 'sets template_engine to :liquid' do
6
+ expect(Rails.configuration.app_generators.rails[:template_engine]).to eq(:liquid)
7
+ end
8
+ end
9
+ 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,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Liquid
4
+ module Rails
5
+ describe ContentForTag, type: :tag do
6
+ it 'content_for and yield' do
7
+ Liquid::Template.parse(%|{% content_for 'not_authorized1' %}alert('You are not authorized to do that!');{% endcontent_for %}|).render(context)
8
+
9
+ expect_template_result(%|{% yield 'not_authorized1' %}|, "alert('You are not authorized to do that!');")
10
+ end
11
+
12
+ it 'invokes content_for with the same identifier multiple times' do
13
+ Liquid::Template.parse(%|{% content_for 'not_authorized2' %}alert('You are not authorized to do that 1!');{% endcontent_for %}|).render(context)
14
+ Liquid::Template.parse(%|{% content_for 'not_authorized2' %}alert('You are not authorized to do that 2!');{% endcontent_for %}|).render(context)
15
+
16
+ expect_template_result(%|{% yield 'not_authorized2' %}|, "alert('You are not authorized to do that 1!');alert('You are not authorized to do that 2!');")
17
+ end
18
+
19
+ it 'invokes content_for with the same identifier multiple times and flush' do
20
+ Liquid::Template.parse(%|{% content_for 'not_authorized3' %}alert('You are not authorized to do that 1!');{% endcontent_for %}|).render(context)
21
+ Liquid::Template.parse(%|{% content_for 'not_authorized3' flush true %}alert('You are not authorized to do that 2!');{% endcontent_for %}|).render(context)
22
+
23
+ expect_template_result(%|{% yield 'not_authorized3' %}|, "alert('You are not authorized to do that 2!');")
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,16 @@
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
+ view.stub(:protect_against_forgery?).and_return(true)
10
+
11
+ result = Liquid::Template.parse('{% csrf_meta_tags %}').render(context)
12
+ expect(result).to eq(%|<meta content=\"authenticity_token\" name=\"csrf-param\" />\n<meta content=\"#{view.form_authenticity_token}\" name=\"csrf-token\" />|)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,31 @@
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
+ var _gaq = _gaq || [];
16
+ _gaq.push(['_setAccount', 'UA-XXXXX-X']);
17
+ _gaq.push(['_trackPageview']);
18
+
19
+ (function() {
20
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
21
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
22
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
23
+ })();
24
+
25
+ </script>
26
+ }
27
+ )
28
+ end
29
+ end
30
+ end
31
+ 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,96 @@
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 '#page_size' do
31
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.page_size }}{% endpaginate %}", '2', { 'post' => @post_drop })
32
+ end
33
+
34
+ it '#pages' do
35
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.pages }}{% endpaginate %}", '3', { 'post' => @post_drop })
36
+ end
37
+
38
+ it '#items' do
39
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.items }}{% endpaginate %}", '5', { 'post' => @post_drop })
40
+ end
41
+
42
+ it '#previous' do
43
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.previous }}{% endpaginate %}", '', { 'post' => @post_drop })
44
+ end
45
+
46
+ it '#next' do
47
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.next }}{% endpaginate %}", %|{"title"=>"Next &raquo;", "url"=>"?page=2", "is_link"=>true}|, { 'post' => @post_drop })
48
+ end
49
+
50
+ it '#parts' do
51
+ 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 })
52
+ end
53
+ end
54
+
55
+ context 'last_page' do
56
+ before(:all) { controller.params[:page] = 3 }
57
+
58
+ it 'returns the page size' do
59
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.collection | size }}{% endpaginate %}", '1', { 'post' => @post_drop })
60
+ end
61
+
62
+ it 'returns the comments inside the collection' do
63
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.collection[0].body }}{% endpaginate %}", 'COMMENT 5', { 'post' => @post_drop })
64
+ end
65
+
66
+ it '#current_offset' do
67
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.current_offset }}{% endpaginate %}", '4', { 'post' => @post_drop })
68
+ end
69
+
70
+ it '#page_size' do
71
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.page_size }}{% endpaginate %}", '2', { 'post' => @post_drop })
72
+ end
73
+
74
+ it '#pages' do
75
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.pages }}{% endpaginate %}", '3', { 'post' => @post_drop })
76
+ end
77
+
78
+ it '#items' do
79
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.items }}{% endpaginate %}", '5', { 'post' => @post_drop })
80
+ end
81
+
82
+ it '#previous' do
83
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.previous }}{% endpaginate %}", %|{"title"=>"&laquo; Previous", "url"=>"?page=2", "is_link"=>true}|, { 'post' => @post_drop })
84
+ end
85
+
86
+ it '#next' do
87
+ expect_template_result("{% paginate post.comments by 2 %}{{ paginate.next }}{% endpaginate %}", %||, { 'post' => @post_drop })
88
+ end
89
+
90
+ it '#parts' do
91
+ 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 })
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end