liquid_cms 0.3.0.10 → 0.3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) 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 -2
  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 -28
  27. data/config/initializers/cms/liquid_cms.rb +8 -0
  28. data/config/locales/cms/en.yml +5 -0
  29. data/generators/liquid_cms/templates/migration_rev1.rb +38 -0
  30. data/lib/generators/liquid_cms/install_generator.rb +7 -9
  31. data/lib/generators/liquid_cms/templates/migration_rev1.rb +38 -0
  32. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/sidebar.css +25 -7
  33. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/simple_form.css +79 -4
  34. data/lib/generators/liquid_cms/templates/public/cms/stylesheets/styles.css +0 -8
  35. data/lib/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/test/functional/assets_controller_test.rb +64 -16
  39. data/test/functional/components_controller_test.rb +90 -1
  40. data/test/functional/main_controller_test.rb +21 -0
  41. data/test/integration/pages_test.rb +123 -0
  42. data/test/integration/pages_test_no_context.rb +57 -0
  43. data/test/rails_app/db/migrate/20110329201435_create_liquid_cms_upgrade_rev1.rb +38 -0
  44. data/test/test_helper.rb +2 -0
  45. data/test/test_helpers/asset_helpers.rb +6 -4
  46. data/test/test_helpers/component_helpers.rb +37 -0
  47. data/test/test_helpers/file_helpers.rb +11 -0
  48. data/test/unit/asset_test.rb +114 -8
  49. data/test/unit/component_test.rb +64 -1
  50. data/test/unit/helpers/cms/common_helper_test.rb +4 -0
  51. metadata +37 -6
  52. data/app/views/cms/assets/destroy.js.rjs +0 -2
  53. data/test/rails_app/config/initializers/cms/vestal_versions.rb +0 -11
@@ -3,7 +3,96 @@ require File.expand_path('../../test_helper', __FILE__)
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, relpath|
77
+ post :upload, :zip_file => fixture_file_upload(relpath)
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, relpath|
92
+ post :upload, :zip_file => fixture_file_upload(relpath)
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
@@ -132,6 +132,82 @@ class Cms::PagesTest < ActionController::IntegrationTest
132
132
  assert_select '#content span', "test"
133
133
  end
134
134
  end
135
+
136
+ context "asset_data" do
137
+ should "find assets" do
138
+ @asset = Factory(:image_asset, :context => @company, :custom_height => 200, :custom_width => 200)
139
+
140
+ @page = @company.pages.create :name => 'content', :published => true, :content => <<-LIQUID
141
+ {% asset_data %}
142
+ LIQUID
143
+
144
+ get @page.url
145
+ assert response.body.include?("The required 'tag' parameter is missing.")
146
+
147
+ @page.content = <<-LIQUID
148
+ {% asset_data tag:'test' %}
149
+ <span id="count">{{ assets | size }}</span>
150
+ LIQUID
151
+ @page.save
152
+
153
+ get @page.url
154
+ assert_select '#count', '0'
155
+
156
+ # update the tags
157
+ @asset.tag_list = "test"
158
+ @asset.save
159
+
160
+ @page.content = <<-LIQUID
161
+ {% asset_data tag:'test' random:true %}
162
+ <span id="count">{{ assets | size }}</span>
163
+ {{ assets | first | assign_to: 'meta_asset' }}
164
+ <span class="o_dims">{{ meta_asset.image.original.width }}</span>
165
+ <span class="c_dims">{{ meta_asset.image.custom.width }}</span>
166
+ <span class="name">{{ meta_asset.meta.name_test }}</span>
167
+ <span class="location">{{ meta_asset.meta.location }}</span>
168
+ <span class="none">{{ meta_asset.meta.none }}</span>
169
+ LIQUID
170
+ @page.save
171
+
172
+ get @page.url
173
+ assert_select '#count', '1'
174
+ assert_select '.o_dims', '20'
175
+ assert_select '.c_dims', '20'
176
+ assert_select '.name', ''
177
+ assert_select '.location', ''
178
+ assert_select '.none', ''
179
+
180
+ # update the meta data
181
+ @asset.meta_data = [{:name => 'name_test', :value => 'value test'}, {:name => 'location', :value => 'earth'}]
182
+ @asset.save
183
+
184
+ @page.content = <<-LIQUID
185
+ {% asset_data tag:'test' as:'meta_assets' %}
186
+ <span id="count">{{ meta_assets | size }}</span>
187
+ {{ meta_assets | first | assign_to: 'meta_asset' }}
188
+ <span class="name">{{ meta_asset.meta.name_test }}</span>
189
+ <span class="location">{{ meta_asset.meta.location }}</span>
190
+ <span class="none">{{ meta_asset.meta.none }}</span>
191
+ LIQUID
192
+ @page.save
193
+
194
+ get @page.url
195
+ assert_select '#count', '1'
196
+ assert_select '.name', 'value test'
197
+ assert_select '.location', 'earth'
198
+ assert_select '.none', ''
199
+
200
+ # specify the limit as 0
201
+ @page.content = <<-LIQUID
202
+ {% asset_data tag:'test' as:'meta_assets' random:true limit:0 %}
203
+ <span id="count">{{ meta_assets | size }}</span>
204
+ LIQUID
205
+ @page.save
206
+
207
+ get @page.url
208
+ assert_select '#count', '0'
209
+ end
210
+ end
135
211
  end
136
212
 
137
213
  context "filters" do
@@ -296,4 +372,51 @@ class Cms::PagesTest < ActionController::IntegrationTest
296
372
  end
297
373
  end
298
374
  end
375
+
376
+ =begin
377
+ context "caching" do
378
+ setup do
379
+ ActionController::Base.perform_caching = true
380
+ Rails.cache.clear
381
+ @page = Factory(:page, :context => @company)
382
+ end
383
+
384
+ teardown do
385
+ ActionController::Base.perform_caching = false
386
+ end
387
+
388
+ should "expire the cache when the page is updated" do
389
+ assert_cache_empty
390
+
391
+ get @page.url
392
+ assert_cache_present
393
+
394
+ # updating the page will remove the cache
395
+ put cms_page_path(@page), :content => 'new content'
396
+ assert_cache_empty
397
+
398
+ get @page.url
399
+ assert_cache_present
400
+
401
+ # destroying the page will remove the cache
402
+ delete cms_page_path(@page)
403
+ assert_cache_empty
404
+ end
405
+
406
+ should "generate a cache key" do
407
+ get '/'
408
+ assert_cache_key "views/CONTEXT_PATH_#{@company.id}"
409
+
410
+ get @page.url
411
+ assert_cache_key "views/CONTEXT_PATH_#{@company.id}/page"
412
+
413
+ get @page.url+'?page=1&test=abcde'
414
+ assert_cache_key "views/CONTEXT_PATH_#{@company.id}/page/page=1&test=abcde"
415
+
416
+ # different order sent via url, but the path params will be sorted in the path
417
+ get @page.url+'?test=abcde&page=1'
418
+ assert_cache_key "views/CONTEXT_PATH_#{@company.id}/page/page=1&test=abcde"
419
+ end
420
+ end
421
+ =end
299
422
  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,37 @@
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
+ path = Pathname.new(File.join('public', 'cms', 'temp', name))
16
+ fname = Rails.root.join('test', 'fixtures', path).to_s
17
+
18
+ FileUtils.mkdir_p File.dirname(fname)
19
+
20
+ begin
21
+ Zip::ZipFile.open(fname, Zip::ZipFile::CREATE) do |zipfile|
22
+ zipfile.get_output_stream("test.txt") {}
23
+ zipfile.get_output_stream("test.exe") {} # invalid file ext will be ignored
24
+ zipfile.mkdir("dir")
25
+ zipfile.get_output_stream("dir/test.exe") {}
26
+ zipfile.get_output_stream("dir/test.txt") {}
27
+ zipfile.get_output_stream("../../dir/test.exe") {} # relative path file will be ignored
28
+ zipfile.get_output_stream("../../dir/test.txt") {} # relative path file will be ignored
29
+ end
30
+
31
+ yield fname, path
32
+
33
+ ensure
34
+ cleanup_files 'temp'
35
+ end
36
+ end
37
+ 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