liquid_cms 0.2.0.13 → 0.2.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 (55) hide show
  1. data/CHANGELOG.rdoc +12 -0
  2. data/app/controllers/cms/assets_controller.rb +32 -10
  3. data/app/controllers/cms/components_controller.rb +3 -3
  4. data/app/controllers/cms/main_controller.rb +2 -0
  5. data/app/controllers/cms/pages_controller.rb +2 -2
  6. data/app/helpers/cms/pages_helper.rb +0 -12
  7. data/app/liquid/cms_paperclip_extension.rb +1 -1
  8. data/app/liquid/drops/cms_asset_drop.rb +15 -0
  9. data/app/liquid/filters/cms_filters.rb +1 -1
  10. data/app/liquid/tags/asset_search_tag.rb +26 -0
  11. data/app/liquid/tags/cms/tag_common.rb +29 -0
  12. data/app/liquid/tags/data_tag.rb +59 -0
  13. data/app/models/cms/asset.rb +109 -2
  14. data/app/models/cms/component.rb +21 -17
  15. data/app/models/cms/page.rb +1 -3
  16. data/app/models/cms/tag.rb +21 -0
  17. data/app/models/cms/taggable.rb +78 -0
  18. data/app/models/cms/tagging.rb +6 -0
  19. data/app/views/cms/assets/_asset.html.erb +2 -3
  20. data/app/views/cms/assets/_form.html.erb +53 -3
  21. data/app/views/cms/assets/_list.html.erb +16 -1
  22. data/app/views/cms/assets/_meta_field.html.erb +15 -0
  23. data/app/views/cms/documentation/_cms_drops.html.erb +18 -0
  24. data/app/views/cms/documentation/_cms_tags.html.erb +13 -0
  25. data/app/views/cms/pages/_page.html.erb +1 -3
  26. data/app/views/cms/shared/_sidebar.html.erb +30 -29
  27. data/generators/liquid_cms/lib/insert_commands.rb +14 -0
  28. data/generators/liquid_cms/liquid_cms_generator.rb +5 -1
  29. data/generators/liquid_cms/templates/config/initializers/cms/liquid_cms.rb +8 -0
  30. data/generators/liquid_cms/templates/config/locales/cms/en.yml +5 -0
  31. data/generators/liquid_cms/templates/migration_rev1.rb +38 -0
  32. data/generators/liquid_cms/templates/public/cms/stylesheets/sidebar.css +25 -7
  33. data/generators/liquid_cms/templates/public/cms/stylesheets/simple_form.css +79 -4
  34. data/generators/liquid_cms/templates/public/cms/stylesheets/styles.css +0 -8
  35. data/generators/liquid_cms/templates/public/cms/stylesheets/themes/dark.css +3 -0
  36. data/lib/liquid_cms/configuration.rb +12 -0
  37. data/lib/liquid_cms/version.rb +1 -1
  38. data/rails/init.rb +0 -1
  39. data/test/functional/assets_controller_test.rb +64 -16
  40. data/test/functional/components_controller_test.rb +90 -1
  41. data/test/functional/main_controller_test.rb +21 -0
  42. data/test/integration/pages_test.rb +124 -0
  43. data/test/integration/pages_test_no_context.rb +57 -0
  44. data/test/rails_app/db/migrate/20110329201435_create_liquid_cms_upgrade_rev1.rb +38 -0
  45. data/test/test_helper.rb +2 -0
  46. data/test/test_helpers/asset_helpers.rb +6 -4
  47. data/test/test_helpers/component_helpers.rb +35 -0
  48. data/test/test_helpers/file_helpers.rb +11 -0
  49. data/test/unit/asset_test.rb +114 -8
  50. data/test/unit/component_test.rb +65 -2
  51. data/test/unit/helpers/cms/common_helper_test.rb +4 -0
  52. metadata +35 -7
  53. data/app/views/cms/assets/destroy.js.rjs +0 -2
  54. data/generators/liquid_cms/templates/config/initializers/cms/vestal_versions.rb +0 -9
  55. data/test/rails_app/config/initializers/cms/vestal_versions.rb +0 -9
@@ -3,7 +3,96 @@ require File.dirname(__FILE__) + '/../test_helper'
3
3
  class Cms::ComponentsControllerTest < ActionController::TestCase
4
4
  def setup
5
5
  setup_company_and_login_admin
6
+ @context = Cms::Context.new(@company)
6
7
  end
7
8
 
8
- should "add component tests"
9
+ context "component file" do
10
+ teardown do
11
+ cleanup_components
12
+ end
13
+
14
+ context "editable" do
15
+ setup do
16
+ @file = File.join('path', 'to', 'file.js')
17
+ setup_component Cms::Component.full_path(@context).join(@file)
18
+ end
19
+
20
+ teardown do
21
+ cleanup_components
22
+ end
23
+
24
+ should "edit" do
25
+ get :edit, :url => [@file]
26
+ assert_response :success
27
+ assert_template 'edit'
28
+ end
29
+
30
+ should "update" do
31
+ put :update, :url => [@file], :file_content => 'new content'
32
+ assert_response :redirect
33
+ assert_equal "The component file has been updated.", flash[:notice]
34
+ assert_equal "new content\n", File.read(Cms::Component.full_path(@context).join(@file))
35
+ end
36
+
37
+ should "valid destroy" do
38
+ delete :destroy, :url => [@file]
39
+ assert_response :redirect
40
+ assert_equal "The component has been removed.", flash[:notice]
41
+ end
42
+
43
+ should "invalid destroy" do
44
+ delete :destroy, :url => [@file+'.bak']
45
+ assert_response :redirect
46
+ assert_equal "The component path was invalid.", flash[:error]
47
+ end
48
+ end
49
+
50
+ context "non-editable" do
51
+ setup do
52
+ @file = File.join('path', 'to', 'file.jpg')
53
+ setup_component Cms::Component.full_path(@context).join(@file)
54
+ end
55
+
56
+ should "edit" do
57
+ get :edit, :url => [@file]
58
+ assert_response :redirect
59
+ assert_equal "Not an editable component.", flash[:error]
60
+ end
61
+
62
+ should "update" do
63
+ put :update, :url => [@file], :file_content => 'new content'
64
+ assert_response :redirect
65
+ assert_equal "Not an editable component.", flash[:error]
66
+ end
67
+ end
68
+ end
69
+
70
+ context "upload" do
71
+ teardown do
72
+ cleanup_components
73
+ end
74
+
75
+ should "successfully upload a valid zip" do
76
+ create_zip 'test.zip' do |path|
77
+ post :upload, :zip_file => ActionController::TestUploadedFile.new(path)
78
+ assert_response :redirect
79
+ assert_equal 'The component has been uploaded.', flash[:notice]
80
+
81
+ assert File.exist?(Cms::Component.full_path(@context).join('test.txt'))
82
+ assert !File.exist?(Cms::Component.full_path(@context).join('test.ext'))
83
+ assert File.exist?(Cms::Component.full_path(@context).join('dir', 'test.txt'))
84
+ assert !File.exist?(Cms::Component.full_path(@context).join('dir', 'test.exe'))
85
+ assert !File.exist?(Cms::Component.full_path(@context).join('../../dir', 'test.exe'))
86
+ assert !File.exist?(Cms::Component.full_path(@context).join('../../dir', 'test.txt'))
87
+ end
88
+ end
89
+
90
+ should "produce an error" do
91
+ create_zip 'test.bmp' do |path|
92
+ post :upload, :zip_file => ActionController::TestUploadedFile.new(path)
93
+ assert_response :redirect
94
+ assert_equal 'The component file must be a zip archive.', flash[:error]
95
+ end
96
+ end
97
+ end
9
98
  end
@@ -27,6 +27,27 @@ class Cms::MainControllerTest < ActionController::TestCase
27
27
  assert_response :success
28
28
  assert_select "#assets p.preview", false
29
29
  end
30
+
31
+ should "show no tags" do
32
+ Factory(:image_asset, :context => @company)
33
+
34
+ get :index
35
+ assert_response :success
36
+ assert_select 'li.group.tagged', false
37
+ assert_select 'li.group.untagged', true
38
+ assert_select 'li.group.untagged h4', false
39
+ end
40
+
41
+ should "show tags" do
42
+ tagged = Factory(:image_asset, :context => @company, :tag_list => 'test, this')
43
+ Factory(:image_asset, :context => @company)
44
+
45
+ get :index
46
+ assert_response :success
47
+ assert_select 'li.group.tagged', tagged.tags.count
48
+ assert_select 'li.group.untagged'
49
+ assert_select 'li.group.untagged h4', 'Untagged'
50
+ end
30
51
  end
31
52
 
32
53
  context "permission access" do
@@ -1,4 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/../test_helper'
2
+ require File.dirname(__FILE__) + '/../test_helpers/cache_helper'
2
3
 
3
4
  class Cms::PagesTest < ActionController::IntegrationTest
4
5
 
@@ -121,6 +122,82 @@ class Cms::PagesTest < ActionController::IntegrationTest
121
122
  assert_select '#content span', "test"
122
123
  end
123
124
  end
125
+
126
+ context "asset_data" do
127
+ should "find assets" do
128
+ @asset = Factory(:image_asset, :context => @company, :custom_height => 200, :custom_width => 200)
129
+
130
+ @page = @company.pages.create :name => 'content', :published => true, :content => <<-LIQUID
131
+ {% asset_data %}
132
+ LIQUID
133
+
134
+ get @page.url
135
+ assert response.body.include?("The required 'tag' parameter is missing.")
136
+
137
+ @page.content = <<-LIQUID
138
+ {% asset_data tag:'test' %}
139
+ <span id="count">{{ assets | size }}</span>
140
+ LIQUID
141
+ @page.save
142
+
143
+ get @page.url
144
+ assert_select '#count', '0'
145
+
146
+ # update the tags
147
+ @asset.tag_list = "test"
148
+ @asset.save
149
+
150
+ @page.content = <<-LIQUID
151
+ {% asset_data tag:'test' random:true %}
152
+ <span id="count">{{ assets | size }}</span>
153
+ {{ assets | first | assign_to: 'meta_asset' }}
154
+ <span class="o_dims">{{ meta_asset.image.original.width }}</span>
155
+ <span class="c_dims">{{ meta_asset.image.custom.width }}</span>
156
+ <span class="name">{{ meta_asset.meta.name_test }}</span>
157
+ <span class="location">{{ meta_asset.meta.location }}</span>
158
+ <span class="none">{{ meta_asset.meta.none }}</span>
159
+ LIQUID
160
+ @page.save
161
+
162
+ get @page.url
163
+ assert_select '#count', '1'
164
+ assert_select '.o_dims', '20'
165
+ assert_select '.c_dims', '20'
166
+ assert_select '.name', ''
167
+ assert_select '.location', ''
168
+ assert_select '.none', ''
169
+
170
+ # update the meta data
171
+ @asset.meta_data = [{:name => 'name_test', :value => 'value test'}, {:name => 'location', :value => 'earth'}]
172
+ @asset.save
173
+
174
+ @page.content = <<-LIQUID
175
+ {% asset_data tag:'test' as:'meta_assets' %}
176
+ <span id="count">{{ meta_assets | size }}</span>
177
+ {{ meta_assets | first | assign_to: 'meta_asset' }}
178
+ <span class="name">{{ meta_asset.meta.name_test }}</span>
179
+ <span class="location">{{ meta_asset.meta.location }}</span>
180
+ <span class="none">{{ meta_asset.meta.none }}</span>
181
+ LIQUID
182
+ @page.save
183
+
184
+ get @page.url
185
+ assert_select '#count', '1'
186
+ assert_select '.name', 'value test'
187
+ assert_select '.location', 'earth'
188
+ assert_select '.none', ''
189
+
190
+ # specify the limit as 0
191
+ @page.content = <<-LIQUID
192
+ {% asset_data tag:'test' as:'meta_assets' random:true limit:0 %}
193
+ <span id="count">{{ meta_assets | size }}</span>
194
+ LIQUID
195
+ @page.save
196
+
197
+ get @page.url
198
+ assert_select '#count', '0'
199
+ end
200
+ end
124
201
  end
125
202
 
126
203
  context "filters" do
@@ -279,4 +356,51 @@ class Cms::PagesTest < ActionController::IntegrationTest
279
356
  assert_response 404
280
357
  end
281
358
  end
359
+
360
+ context "caching" do
361
+ setup do
362
+ ActionController::Base.perform_caching = true
363
+ Rails.cache.clear
364
+ @page = Factory(:page, :context => @company)
365
+ end
366
+
367
+ teardown do
368
+ ActionController::Base.perform_caching = false
369
+ end
370
+
371
+ =begin
372
+ should "expire the cache when the page is updated" do
373
+ assert_cache_empty
374
+
375
+ get @page.url
376
+ assert_cache_present
377
+
378
+ # updating the page will remove the cache
379
+ put cms_page_path(@page), :content => 'new content'
380
+ assert_cache_empty
381
+
382
+ get @page.url
383
+ assert_cache_present
384
+
385
+ # destroying the page will remove the cache
386
+ delete cms_page_path(@page)
387
+ assert_cache_empty
388
+ end
389
+
390
+ should "generate a cache key" do
391
+ get '/'
392
+ assert_cache_key "views/CONTEXT_PATH_#{@company.id}"
393
+
394
+ get @page.url
395
+ assert_cache_key "views/CONTEXT_PATH_#{@company.id}/page"
396
+
397
+ get @page.url+'?page=1&test=abcde'
398
+ assert_cache_key "views/CONTEXT_PATH_#{@company.id}/page/page=1&test=abcde"
399
+
400
+ # different order sent via url, but the path params will be sorted in the path
401
+ get @page.url+'?test=abcde&page=1'
402
+ assert_cache_key "views/CONTEXT_PATH_#{@company.id}/page/page=1&test=abcde"
403
+ end
404
+ =end
405
+ end
282
406
  end
@@ -0,0 +1,57 @@
1
+ require File.expand_path('../../no_context_test_helper', __FILE__)
2
+ require File.expand_path('../../test_helpers/cache_helper', __FILE__)
3
+
4
+ class Cms::PagesTestNoContext < ActionController::IntegrationTest
5
+
6
+ def setup
7
+ @company = Factory(:company)
8
+ @user = @company.users.first
9
+ login_company(@user.username, 'password')
10
+ set_company_host(@company)
11
+ end
12
+
13
+ context "caching" do
14
+ setup do
15
+ ActionController::Base.perform_caching = true
16
+ Rails.cache.clear
17
+ @page = Factory(:page)
18
+ end
19
+
20
+ teardown do
21
+ ActionController::Base.perform_caching = false
22
+ end
23
+
24
+ should "expire the cache when the page is updated" do
25
+ assert_cache_empty
26
+
27
+ get @page.url
28
+ assert_cache_present
29
+
30
+ # updating the page will remove the cache
31
+ put cms_page_path(@page), :content => 'new content'
32
+ assert_cache_empty
33
+
34
+ get @page.url
35
+ assert_cache_present
36
+
37
+ # destroying the page will remove the cache
38
+ delete cms_page_path(@page)
39
+ assert_cache_empty
40
+ end
41
+
42
+ should "generate a cache key" do
43
+ get '/'
44
+ assert_cache_key "views/NO_CONTEXT"
45
+
46
+ get @page.url
47
+ assert_cache_key "views/NO_CONTEXT/page"
48
+
49
+ get @page.url+'?page=1&test=abcde'
50
+ assert_cache_key "views/NO_CONTEXT/page/page=1&test=abcde"
51
+
52
+ # different order sent via url, but the path params will be sorted in the path
53
+ get @page.url+'?test=abcde&page=1'
54
+ assert_cache_key "views/NO_CONTEXT/page/page=1&test=abcde"
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,38 @@
1
+ class CreateLiquidCmsUpgradeRev1 < ActiveRecord::Migration
2
+ def self.up
3
+ change_table :cms_assets do |t|
4
+ t.integer :custom_height
5
+ t.integer :custom_width
6
+ t.text :meta_data # serialized yaml
7
+ end
8
+
9
+ drop_table :versions
10
+
11
+ create_table :cms_tags do |t|
12
+ t.column :name, :string
13
+ end
14
+
15
+ create_table :cms_taggings do |t|
16
+ t.column :tag_id, :integer
17
+ t.column :taggable_id, :integer
18
+ t.column :taggable_type, :string
19
+
20
+ t.column :created_at, :datetime
21
+ end
22
+
23
+ add_index :cms_taggings, :tag_id
24
+ add_index :cms_taggings, [:taggable_id, :taggable_type]
25
+ end
26
+
27
+ def self.down
28
+ drop_table :cms_taggings
29
+ drop_table :cms_tags
30
+
31
+ create_table :versions do |t|
32
+ end
33
+
34
+ change_table :cms_assets do |t|
35
+ t.remove :custom_height, :custom_width, :meta_data
36
+ end
37
+ end
38
+ end
data/test/test_helper.rb CHANGED
@@ -32,12 +32,14 @@ end
32
32
 
33
33
  require 'test_helpers/login_methods'
34
34
  require 'test_helpers/asset_helpers'
35
+ require 'test_helpers/component_helpers'
35
36
 
36
37
  class ActionController::TestCase
37
38
  include AssetHelpers
38
39
  end
39
40
  class ActiveSupport::TestCase
40
41
  include AssetHelpers
42
+ include ComponentHelpers
41
43
  end
42
44
 
43
45
 
@@ -1,12 +1,14 @@
1
+ require File.expand_path('../file_helpers', __FILE__)
2
+
1
3
  module AssetHelpers
4
+ include FileHelpers
5
+
2
6
  def setup_asset(file_name)
3
- FileUtils.mkdir_p File.dirname(file_name)
4
- FileUtils.touch file_name
7
+ setup_file file_name
5
8
  end
6
9
 
7
10
  def cleanup_assets
8
- FileUtils.rm_rf TestConfig.paperclip_test_root
9
- FileUtils.rm_rf Rails.root.join('public', 'cms', 'assets')
11
+ cleanup_files 'assets'
10
12
  end
11
13
 
12
14
  def asset_path
@@ -0,0 +1,35 @@
1
+ require File.expand_path('../file_helpers', __FILE__)
2
+
3
+ module ComponentHelpers
4
+ include FileHelpers
5
+
6
+ def setup_component(file_name)
7
+ setup_file file_name
8
+ end
9
+
10
+ def cleanup_components
11
+ cleanup_files 'components'
12
+ end
13
+
14
+ def create_zip(name)
15
+ fname = Rails.root.join('public', 'cms', 'temp').join(name)
16
+ FileUtils.mkdir_p File.dirname(fname)
17
+
18
+ begin
19
+ Zip::ZipFile.open(fname, Zip::ZipFile::CREATE) do |zipfile|
20
+ zipfile.get_output_stream("test.txt") {}
21
+ zipfile.get_output_stream("test.exe") {} # invalid file ext will be ignored
22
+ zipfile.mkdir("dir")
23
+ zipfile.get_output_stream("dir/test.exe") {}
24
+ zipfile.get_output_stream("dir/test.txt") {}
25
+ zipfile.get_output_stream("../../dir/test.exe") {} # relative path file will be ignored
26
+ zipfile.get_output_stream("../../dir/test.txt") {} # relative path file will be ignored
27
+ end
28
+
29
+ yield fname
30
+
31
+ ensure
32
+ cleanup_files 'temp'
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,11 @@
1
+ module FileHelpers
2
+ def setup_file(file_name)
3
+ FileUtils.mkdir_p File.dirname(file_name)
4
+ FileUtils.touch file_name
5
+ end
6
+
7
+ def cleanup_files(dir)
8
+ FileUtils.rm_rf TestConfig.paperclip_test_root
9
+ FileUtils.rm_rf Rails.root.join('public', 'cms', dir)
10
+ end
11
+ end