liquid_cms 0.2.0.9 → 0.2.0.10

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2.0.10
2
+
3
+ * Enhancements
4
+ * Allow text based assets to be editable inline.
5
+
1
6
  == 0.2.0.3
2
7
 
3
8
  Updated codemirror to 0.9
data/README.rdoc CHANGED
@@ -58,6 +58,12 @@ In order to expose data in your application in the templates, liquid filters, dr
58
58
 
59
59
  A set of filters, drops and tags are provided in addition to the defaults provided by liquid. The documentation link accessible in the CMS provides additional details.
60
60
 
61
+ = Upgrading
62
+
63
+ To upgrade the liquid_cms engine once you've installed a newer gem, simply re-run the liquid_cms generator. If any differences are found in files, you'll be prompted to overwrite or compare versions.
64
+
65
+ If you're upgrading to the rails 3 version of the gem from the rails 2 version of the gem, it's recommended that you run the generator with the previous CMS generated files removed from your app and then integrate any customizations back into the application.
66
+
61
67
  = Contribution
62
68
 
63
69
  If you experience any issues with this CMS engine, please open a bug report. Contributions to improve this engine are extremely welcome. A 1.0 release will be made when the engine has a bit more _polish_ on it.
data/Rakefile CHANGED
@@ -7,13 +7,23 @@ require 'rake/testtask'
7
7
  desc 'Default: run tests.'
8
8
  task :default => :test
9
9
 
10
+ test_types = %w(unit functional integration)
11
+
10
12
  desc 'Test the liquid_cms gem.'
11
- task :test => ['test:unit', 'test:functional', 'test:integration']
13
+ task :test => test_types.collect{|t| ["test:#{t}", "test:#{t}:no_context"]}.flatten
12
14
 
13
- %w(unit functional integration).each do |test|
14
- desc "Run the #{test} tests for the liquid_cms gem."
15
+ test_types.each do |test|
16
+ desc "Run the #{test} tests for the liquid_cms gem"
15
17
  Rake::TestTask.new("test:#{test}") do |t|
16
18
  t.pattern = "test/#{test}/*_test.rb"
17
19
  t.verbose = true
18
20
  end
19
21
  end
22
+
23
+ test_types.each do |test|
24
+ desc "Run the #{test} tests for the liquid_cms gem (no context)"
25
+ Rake::TestTask.new("test:#{test}:no_context") do |t|
26
+ t.pattern = "test/#{test}/*_test_no_context.rb"
27
+ t.verbose = true
28
+ end
29
+ end
data/TODO.rdoc CHANGED
@@ -4,4 +4,5 @@
4
4
  * Implement caching and expiration logic.
5
5
  * Provide example apache/nginx/etc. conf files that properly scope cms assets for each context.
6
6
  * Generate CMS documentation from rdoc comments in source files.
7
+ * Search functions. Find templates based on search text.
7
8
  * Missing tests... add more coverage.
@@ -25,7 +25,14 @@ class Cms::AssetsController < Cms::MainController
25
25
 
26
26
  def update
27
27
  @asset = @context.assets.find params[:id]
28
- if @asset.update_attributes params[:cms_asset]
28
+
29
+ success = if params[:file_content].present?
30
+ @asset.write params[:file_content]
31
+ else
32
+ @asset.update_attributes params[:cms_asset]
33
+ end
34
+
35
+ if success
29
36
  flash[:notice] = t('assets.flash.updated')
30
37
  redirect_to cms_root_path
31
38
  else
@@ -15,13 +15,13 @@ class Cms::ComponentsController < Cms::MainController
15
15
  def update
16
16
  if Cms::Component.editable?(@path)
17
17
  @component = Cms::Component.new(@context, @path)
18
- @component.write params[:contents]
18
+ @component.write params[:file_content]
19
19
 
20
20
  flash[:notice] = "Component file updated."
21
- redirect_to :controller => 'cms/components', :action => 'edit', :url => @path
21
+ redirect_to cms_root_path
22
22
  else
23
23
  flash[:error] = "Not an editable file."
24
- redirect_to cms_root_path
24
+ redirect_to :controller => 'cms/components', :action => 'edit', :url => @path
25
25
  end
26
26
  end
27
27
 
@@ -6,8 +6,8 @@ module Paperclip
6
6
  {}.tap do |h|
7
7
  all_styles = self.styles.keys + ['original']
8
8
  all_styles.each do |style|
9
- g = Paperclip::Geometry.from_file(self.path(style))
10
- h[style] = {'width' => g.width.to_i, 'height' => g.height.to_i, 'url' => self.url(style)}
9
+ g = Paperclip::Geometry.from_file(self.path(style)) rescue nil
10
+ h[style] = {'width' => g.width.to_i, 'height' => g.height.to_i, 'url' => self.url(style)} unless g.nil?
11
11
  end
12
12
  end
13
13
  end
@@ -18,11 +18,32 @@ module Cms
18
18
  end
19
19
 
20
20
  def image?
21
- !(asset_content_type =~ /^image.*/).nil?
21
+ !(asset_content_type =~ /^image.*/).blank?
22
22
  end
23
23
 
24
24
  def icon?
25
- !(asset_content_type =~ /icon$/).nil?
25
+ # accepts ico or icon
26
+ !(asset_content_type =~ /icon?$/).blank?
27
+ end
28
+
29
+ def editable?
30
+ !(asset_content_type =~ /(javascript|css|xml|html)$/).blank?
31
+ end
32
+
33
+ def read
34
+ return '' if !editable?
35
+ asset.to_file(:original).read
36
+ end
37
+
38
+ def write(content)
39
+ return false if content.blank? || !editable?
40
+
41
+ fname = asset.path(:original)
42
+ File.exist?(fname).tap do |exist|
43
+ File.open(fname, 'w') do |f|
44
+ f.puts content
45
+ end if exist
46
+ end
26
47
  end
27
48
 
28
49
  protected
@@ -42,9 +42,9 @@ class Cms::Component
42
42
  def read
43
43
  return '' if @path.blank? || !self.class.editable?(@path)
44
44
 
45
- base = self.class.full_path(@context).join(@path).to_s
46
- if File.exist?(base)
47
- File.open(base).readlines
45
+ fname = self.class.full_path(@context).join(@path).to_s
46
+ if File.exist?(fname)
47
+ File.open(fname).read
48
48
  else
49
49
  ''
50
50
  end
@@ -53,30 +53,25 @@ class Cms::Component
53
53
  def write(content)
54
54
  return false if content.blank? || @path.blank? || !self.class.editable?(@path)
55
55
 
56
- base = self.class.full_path(@context).join(@path).to_s
57
- if File.exist?(base)
58
- File.open(base, 'w') do |f|
56
+ fname = self.class.full_path(@context).join(@path).to_s
57
+ File.exist?(fname).tap do |exist|
58
+ File.open(fname, 'w') do |f|
59
59
  f.puts content
60
- end
61
- else
62
- ''
60
+ end if exist
63
61
  end
64
62
  end
65
63
 
66
64
  def delete
67
65
  return false if @path.blank?
68
66
 
69
- base = self.class.full_path(@context).join(@path)
70
- if File.exist?(base)
71
- FileUtils.rm_rf base
72
- true
73
- else
74
- false
67
+ fname = self.class.full_path(@context).join(@path)
68
+ File.exist?(fname).tap do |exist|
69
+ FileUtils.rm_rf fname if exist
75
70
  end
76
71
  end
77
72
 
78
73
  def self.editable?(file)
79
- !(file =~ /\.(js|css|html|xml)$/).nil?
74
+ !(file =~ /\.(js|css|html|xml)$/).blank?
80
75
  end
81
76
 
82
77
  protected
@@ -100,7 +100,7 @@ module Cms
100
100
 
101
101
  def content=(text)
102
102
  write_attribute :content, text
103
- self.is_layout_page = !(text =~ /\{\{\s?content_for_layout\s?\}\}/).nil?
103
+ self.is_layout_page = !(text =~ /\{\{\s?content_for_layout\s?\}\}/).blank?
104
104
  end
105
105
 
106
106
  protected
@@ -1,6 +1,18 @@
1
- <div class="formContainer form">
2
- <% simple_form_for @asset, :html => {:multipart => true} do |f| %>
3
- <%= f.input :asset, :as => :file %>
4
- <%= f.commit_button_or_cancel %>
1
+ <% simple_form_for @asset, :html => {:multipart => true} do |f| %>
2
+ <%= f.input :asset, :as => :file %>
3
+
4
+ <% if f.object.editable? %>
5
+ <p class="break">
6
+ <em>or edit the contents...</em>
7
+ </p>
8
+
9
+ <div class="text required">
10
+ <%= label_tag :file_content, 'Content', :class => 'text required' %> <%= text_area_tag :file_content, f.object.read, :rows => 40, :class => 'text required' %>
11
+ <span class="hint"><%= t('simple_form.hints.cms_asset.file_content') %></span>
12
+ </div>
13
+
14
+ <%= codemirror_edit Cms::Editable::content_type(@asset.asset_file_name), 'form.simple_form', 'file_content' %>
5
15
  <% end %>
6
- </div>
16
+
17
+ <%= f.commit_button_or_cancel %>
18
+ <% end %>
@@ -1,12 +1,14 @@
1
- <h2><%= @asset.asset_file_name %></h2>
1
+ <div class="basic">
2
+ <h2><%= @asset.asset_file_name %></h2>
2
3
 
3
- <% if @asset.image? %>
4
- <%= image_tag @asset.asset.url %>
5
- <% else %>
6
- <p>Open: <%= link_to @asset.asset_file_name, @asset.asset.url %></p>
7
- <% end %>
4
+ <% if @asset.image? %>
5
+ <%= image_tag @asset.asset.url %>
6
+ <% else %>
7
+ <p>Open: <%= link_to @asset.asset_file_name, @asset.asset.url %></p>
8
+ <% end %>
8
9
 
9
- <p>Filesize: <%= number_to_human_size(@asset.asset_file_size) %></p>
10
- <p>Last Updated: <%= @asset.asset_updated_at.to_formatted_s(:long) %></p>
10
+ <p>Filesize: <%= number_to_human_size(@asset.asset_file_size) %></p>
11
+ <p>Last Updated: <%= @asset.asset_updated_at.to_formatted_s(:long) %></p>
11
12
 
12
- <p><%= link_to 'Edit Asset', edit_cms_asset_path(@asset) %></p>
13
+ <p><%= link_to 'Edit Asset', edit_cms_asset_path(@asset) %></p>
14
+ </div>
@@ -1,18 +1,17 @@
1
1
  <h2>Edit Component File</h2>
2
2
 
3
- <p>No liquid support currently for editing components.</p>
4
-
5
3
  <% form_tag({:controller => 'cms/components', :action => 'update', :url => CGI::escape(@component.path)}, :class => 'simple_form') do %>
6
4
  <div class="string required">
7
5
  <%= label_tag :name, nil, :class => 'string required' %> <%= text_field_tag :name, @component.path, :readonly => true, :class => 'string required' %>
8
6
  </div>
9
7
  <div class="text required">
10
- <%= label_tag :contents, nil, :class => 'text required' %> <%= text_area_tag :contents, @component.read, :rows => 40, :class => 'text required' %>
8
+ <%= label_tag :file_content, 'Content', :class => 'text required' %> <%= text_area_tag :file_content, @component.read, :rows => 40, :class => 'text required' %>
9
+ <span class="hint"><%= t('simple_form.hints.cms_component.file_content') %></span>
11
10
  </div>
12
11
 
13
12
  <div class="buttons">
14
- <%= submit_tag 'Update', :class => 'update' %> or <%= link_to 'Cancel', :back, :class => 'cancel' %>
13
+ <%= submit_tag 'Update', :class => 'update' %> or <%= link_to t('simple_form.buttons.cancel'), :back, :class => 'cancel' %>
15
14
  </div>
16
15
  <% end %>
17
16
 
18
- <%= codemirror_edit Cms::Editable::content_type(@component.path), 'form.simple_form', 'contents' %>
17
+ <%= codemirror_edit Cms::Editable::content_type(@component.path), 'form.simple_form', 'file_content' %>
@@ -1,14 +1,12 @@
1
- <div class="formContainer form">
2
- <% simple_form_for @page do |f| %>
3
- <%= f.input :name %>
4
- <%= f.input :slug, :required => false %>
5
- <%= f.input :content, :input_html => {:rows => 30, :spellcheck => false} %>
6
- <%= f.input :layout_page_id, :collection => layouts_for_page(@page).collect{|pg| [pg.to_s, pg.id]}, :include_blank => '-- layout file --', :required => false unless layouts_for_page(@page).empty? %>
7
- <%= f.input :published, :required => false %>
8
- <%= f.input :root, :required => false %>
1
+ <% simple_form_for @page do |f| %>
2
+ <%= f.input :name %>
3
+ <%= f.input :slug, :required => false %>
4
+ <%= f.input :content, :input_html => {:rows => 30, :spellcheck => false} %>
5
+ <%= f.input :layout_page_id, :collection => layouts_for_page(@page).collect{|pg| [pg.to_s, pg.id]}, :include_blank => '-- layout file --', :required => false unless layouts_for_page(@page).empty? %>
6
+ <%= f.input :published, :required => false %>
7
+ <%= f.input :root, :required => false %>
9
8
 
10
- <%= f.commit_button_or_cancel %>
11
- <% end %>
12
- </div>
9
+ <%= f.commit_button_or_cancel %>
10
+ <% end %>
13
11
 
14
12
  <%= codemirror_edit @page.content_type, 'form.simple_form.cms_page', 'cms_page_content' %>
@@ -4,7 +4,7 @@ class SimpleForm::FormBuilder
4
4
  String.new.tap do |html|
5
5
  html << button(:submit)
6
6
  html << " or "
7
- html << template.link_to('Cancel', :back, :class => 'cancel')
7
+ html << template.link_to(t('simple_form.buttons.cancel'), :back, :class => 'cancel')
8
8
  end
9
9
  end
10
10
  end
@@ -38,6 +38,7 @@ en:
38
38
  "yes": 'Yes'
39
39
  "no": 'No'
40
40
  buttons:
41
+ cancel: 'Cancel'
41
42
  create: 'Create %{model}'
42
43
  update: 'Update %{model}'
43
44
  submit: 'Submit %{model}'
@@ -60,3 +61,10 @@ en:
60
61
  content: 'To create a layout page, add the <em>{{ content_for_layout }}</em> tag which will act as a placeholder for the contents of another page. Use ctrl+s to save.'
61
62
  slug: 'The url path that will be used to access this page. Defaults to the page name if not provided. ie. /name.<br/> Ex. /home_page'
62
63
  layout_page_id: 'Optional page that will be used as this pages layout. Ie. This pages content will be inserted into the layout page where the <em>{{ content_for_layout }}</em> tag is specified.'
64
+ cms_component:
65
+ file_content: '<em>No liquid support for editing components.</em> Use ctrl+s to save.'
66
+ cms_asset:
67
+ asset: 'Upload an asset file.'
68
+ file_content: '<em>No liquid support for editing assets.</em> Use ctrl+s to save.'
69
+ edit:
70
+ asset: 'An existing file has been uploaded. Upload a new file to replace it.'
@@ -43,7 +43,7 @@ form.simple_form a.cancel:hover {
43
43
  background: -webkit-gradient(linear, left top, left bottom, color-stop(0,#F55), color-stop(1.0,#C11));
44
44
  }
45
45
 
46
- form.simple_form div.string, form.simple_form div.text, form.simple_form div.boolean, div.select {
46
+ form.simple_form div.string, form.simple_form div.text, form.simple_form div.boolean, form.simple_form div.select, form.simple_form div.file {
47
47
  margin-bottom: 1.3em;
48
48
  }
49
49
  form.simple_form label {
@@ -12,10 +12,10 @@ body {
12
12
  .cms_documentation #content {
13
13
  color: #EEE;
14
14
  }
15
- .cms_documentation #content a {
15
+ #content .basic a, .cms_documentation #content a {
16
16
  color: #FFE900;
17
17
  }
18
- .cms_components #content p {
18
+ #content .basic p, .cms_components #content p {
19
19
  color: white;
20
20
  }
21
21
  .cms_documentation span.function {
@@ -9,7 +9,7 @@ module Cms
9
9
  mattr_reader :context_class
10
10
  def self.context_class=(klass)
11
11
  @@context_class = klass
12
- return if klass.nil?
12
+ return if klass.nil? || ENV['NO_CONTEXT'] == 'true'
13
13
 
14
14
  Dispatcher.to_prepare {
15
15
  eval(klass.to_s).extend Cms::ContextAssociation
@@ -1,3 +1,3 @@
1
1
  module Cms
2
- VERSION = "0.2.0.9"
2
+ VERSION = "0.2.0.10"
3
3
  end
data/liquid_cms.gemspec CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.add_development_dependency 'factory_girl', "~> 1.2.3"
30
30
  s.add_development_dependency 'shoulda', "~> 2.10.3"
31
+ s.add_development_dependency 'mocha'
31
32
 
32
33
  test_files = `git ls-files test/`.split("\n")
33
34
  all_files = `git ls-files`.split("\n")
@@ -11,3 +11,10 @@ Factory.define :pdf_asset, :class => Cms::Asset do |a|
11
11
  a.asset_file_size 1.megabyte
12
12
  a.asset_updated_at Time.now
13
13
  end
14
+
15
+ Factory.define :js_asset, :class => Cms::Asset do |a|
16
+ a.asset_file_name 'test.js'
17
+ a.asset_content_type 'text/javascript'
18
+ a.asset_file_size 1.megabyte
19
+ a.asset_updated_at Time.now
20
+ end
@@ -7,79 +7,119 @@ class Cms::AssetsControllerTest < ActionController::TestCase
7
7
  end
8
8
 
9
9
  context "actions" do
10
- should "show the image asset" do
11
- asset = Factory(:image_asset, :context => @company)
12
- get :show, :id => asset
13
- assert_response :success
14
- assert_select '#content img'
15
- assert_select 'p', :text => /Open/, :count => 0
16
- assert_select 'p', /Filesize/
17
- assert_select 'p', /Last Updated/
10
+ context "new" do
11
+ should "show the new form" do
12
+ get :new
13
+ assert_select 'div.text', false
14
+ #assert_select 'div.file .hint', 'Upload an asset file.'
15
+ end
18
16
  end
19
17
 
20
- should "show the non-image asset" do
21
- asset = Factory(:pdf_asset, :context => @company)
22
- get :show, :id => asset
23
- assert_response :success
24
- assert_select '#content img', false
25
- assert_select 'p', :text => /Open/, :count => 1
26
- assert_select 'p', /Filesize/
27
- assert_select 'p', /Last Updated/
18
+ context "show" do
19
+ should "show an image asset" do
20
+ asset = Factory(:image_asset, :context => @company)
21
+ get :show, :id => asset
22
+ assert_response :success
23
+ assert_select '#content img'
24
+ assert_select 'p', :text => /Open/, :count => 0
25
+ assert_select 'p', /Filesize/
26
+ assert_select 'p', /Last Updated/
27
+ end
28
+
29
+ should "show a non-image asset" do
30
+ asset = Factory(:pdf_asset, :context => @company)
31
+ get :show, :id => asset
32
+ assert_response :success
33
+ assert_select '#content img', false
34
+ assert_select 'p', :text => /Open/, :count => 1
35
+ assert_select 'p', /Filesize/
36
+ assert_select 'p', /Last Updated/
37
+ end
28
38
  end
29
39
 
30
- should "edit asset" do
31
- asset = Factory(:pdf_asset, :context => @company)
32
- assert_equal 'test.pdf', asset.asset_file_name
40
+ context "edit" do
41
+ should "show form for an editable asset with a textarea" do
42
+ Cms::Asset.any_instance.stubs(:asset).returns(stub(:to_file => stub(:read => 'test contents')))
43
+ asset = Factory(:js_asset, :context => @company)
44
+
45
+ get :edit, :id => asset.id
46
+ assert_select 'div.text', true
47
+ assert_select 'p.break', :text => 'or edit the contents...', :count => 1
48
+ #assert_select 'div.file .hint', 'An existing file has been uploaded. Upload a new file to replace it.'
49
+ end
50
+
51
+ should "show form for an editable asset without a textarea" do
52
+ asset = Factory(:pdf_asset, :context => @company)
53
+
54
+ get :edit, :id => asset.id
55
+ assert_select 'div.text', false
56
+ assert_select 'p.break', :text => 'or edit the contents...', :count => 0
57
+ #assert_select 'div.file .hint', 'An existing file has been uploaded. Upload a new file to replace it.'
58
+ end
59
+ end
33
60
 
34
- new_asset_file = 'new_test.pdf'
35
- setup_asset new_asset_file
61
+ context "update" do
62
+ teardown do
63
+ cleanup_assets
64
+ end
36
65
 
37
- put :update, :id => asset, :cms_asset => {:asset => ActionController::TestUploadedFile.new(asset_file(new_asset_file))}
38
- assert_response :redirect
39
- assert_redirected_to cms_root_path
66
+ should "upload a new asset file" do
67
+ asset = Factory(:pdf_asset, :context => @company)
68
+ assert_equal 'test.pdf', asset.asset_file_name
40
69
 
41
- # check that the file name updated
42
- assert_equal new_asset_file, asset.reload.asset_file_name
70
+ new_asset_file = asset_file('new_test.pdf')
71
+ setup_asset new_asset_file
43
72
 
44
- cleanup_assets
45
- end
73
+ put :update, :id => asset, :cms_asset => {:asset => ActionController::TestUploadedFile.new(new_asset_file)}
74
+ assert_response :redirect
75
+ assert_redirected_to cms_root_path
46
76
 
47
- should "destroy asset via HTML :DELETE" do
48
- asset = Factory(:pdf_asset, :context => @company)
49
- assert_not_nil @company.assets.find_by_id(asset.id)
77
+ # check that the file name updated
78
+ assert_equal File.basename(new_asset_file), asset.reload.asset_file_name
79
+ end
50
80
 
51
- delete :destroy, :id => asset
52
- assert_response :redirect
53
- assert_redirected_to cms_root_path
54
- assert_nil @company.assets.find_by_id(asset.id)
55
- end
81
+ should "modify the contents of an editable asset file" do
82
+ asset = Factory(:pdf_asset, :context => @company)
83
+ put :update, :id => asset, :file_content => 'new content'
84
+ assert_response :success
85
+ assert_template 'edit'
86
+ end
56
87
 
57
- should "destroy asset via XHR :DELETE" do
58
- asset = Factory(:pdf_asset, :context => @company)
59
- assert_not_nil @company.assets.find_by_id(asset.id)
88
+ should "modify the contents of an non-editable asset file" do
89
+ asset = Factory(:js_asset, :context => @company)
60
90
 
61
- xhr :delete, :destroy, :id => asset
62
- assert_response :success
63
- assert_nil @company.assets.find_by_id(asset.id)
91
+ asset_file = asset_file(asset.asset_file_name)
92
+ setup_asset asset_file
93
+
94
+ Cms::Asset.any_instance.stubs(:asset => stub(:path => asset_file))
95
+ Cms::Asset.any_instance.expects(:write).with('new content').returns(true)
96
+
97
+ put :update, :id => asset, :file_content => 'new content'
98
+ assert_response :redirect
99
+ end
64
100
  end
65
- end
66
101
 
67
- protected
68
- def setup_asset(file_name)
69
- FileUtils.mkdir_p asset_path
70
- FileUtils.touch asset_file(file_name)
71
- end
102
+ context "destroy" do
103
+ setup do
104
+ @asset = Factory(:pdf_asset, :context => @company)
105
+ end
72
106
 
73
- def cleanup_assets
74
- FileUtils.rm_rf TestConfig.paperclip_test_root
75
- FileUtils.rm_rf Rails.root.join('public', 'cms', 'assets')
76
- end
107
+ should "destroy asset via HTML :DELETE" do
108
+ assert_not_nil @company.assets.find_by_id(@asset.id)
77
109
 
78
- def asset_path
79
- TestConfig.paperclip_test_root + '/assets'
80
- end
110
+ delete :destroy, :id => @asset
111
+ assert_response :redirect
112
+ assert_redirected_to cms_root_path
113
+ assert_nil @company.assets.find_by_id(@asset.id)
114
+ end
81
115
 
82
- def asset_file(file_name)
83
- asset_path + "/" + file_name
116
+ should "destroy asset via XHR :DELETE" do
117
+ assert_not_nil @company.assets.find_by_id(@asset.id)
118
+
119
+ xhr :delete, :destroy, :id => @asset
120
+ assert_response :success
121
+ assert_nil @company.assets.find_by_id(@asset.id)
122
+ end
123
+ end
84
124
  end
85
125
  end
@@ -0,0 +1,3 @@
1
+ ENV['NO_CONTEXT'] = 'true'
2
+
3
+ require File.dirname(__FILE__) + '/test_helper'
data/test/test_helper.rb CHANGED
@@ -5,6 +5,12 @@ $:.unshift File.dirname(__FILE__)
5
5
  require "rails_app/config/environment"
6
6
  require 'test_help'
7
7
 
8
+ if ENV['NO_CONTEXT'] == 'true'
9
+ Cms.setup do |config|
10
+ config.context_class = nil
11
+ end
12
+ end
13
+
8
14
  ActiveRecord::Migration.verbose = false
9
15
  ActiveRecord::Base.logger = Logger.new(nil)
10
16
  ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
@@ -25,6 +31,15 @@ module TestConfig
25
31
  end
26
32
 
27
33
  require 'test_helpers/login_methods'
34
+ require 'test_helpers/asset_helpers'
35
+
36
+ class ActionController::TestCase
37
+ include AssetHelpers
38
+ end
39
+ class ActiveSupport::TestCase
40
+ include AssetHelpers
41
+ end
42
+
28
43
 
29
44
  class ActiveSupport::TestCase
30
45
  self.use_transactional_fixtures = true
@@ -0,0 +1,19 @@
1
+ module AssetHelpers
2
+ def setup_asset(file_name)
3
+ FileUtils.mkdir_p File.dirname(file_name)
4
+ FileUtils.touch file_name
5
+ end
6
+
7
+ def cleanup_assets
8
+ FileUtils.rm_rf TestConfig.paperclip_test_root
9
+ FileUtils.rm_rf Rails.root.join('public', 'cms', 'assets')
10
+ end
11
+
12
+ def asset_path
13
+ TestConfig.paperclip_test_root + '/assets'
14
+ end
15
+
16
+ def asset_file(file_name)
17
+ asset_path + "/" + file_name
18
+ end
19
+ end
@@ -0,0 +1,14 @@
1
+ class ActionController::IntegrationTest
2
+ def assert_cache_key(key, clear = true)
3
+ assert_equal key, Rails.cache.instance_variable_get(:@data).to_a.try(:first).try(:first)
4
+ Rails.cache.clear if clear == true
5
+ end
6
+
7
+ def assert_cache_present
8
+ assert Rails.cache.instance_variable_get(:@data).present?
9
+ end
10
+
11
+ def assert_cache_empty
12
+ assert Rails.cache.instance_variable_get(:@data).blank?
13
+ end
14
+ end
@@ -1,8 +1,93 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
1
+ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  class Cms::AssetTest < ActiveSupport::TestCase
4
- # Replace this with your real tests.
5
- test "the truth" do
6
- assert true
4
+ def setup
5
+ @context = Factory(:company)
6
+ end
7
+
8
+ def teardown
9
+ cleanup_assets
10
+ end
11
+
12
+ context "type checks" do
13
+ setup do
14
+ @asset = Factory(:image_asset, :context => @context)
15
+ end
16
+
17
+ context "new image" do
18
+ setup do
19
+ @asset = Cms::Asset.new
20
+ end
21
+
22
+ should "not be an image" do
23
+ assert !@asset.image?
24
+ end
25
+ should "not be an icon" do
26
+ assert !@asset.icon?
27
+ end
28
+ should "not be editable" do
29
+ assert !@asset.editable?
30
+ end
31
+ should "not be able to read or write" do
32
+ assert_equal '', @asset.read
33
+ assert_equal false, @asset.write('test')
34
+ end
35
+ end
36
+
37
+ context "image" do
38
+ should "be an image" do
39
+ assert @asset.image?
40
+ end
41
+ should "not be an icon" do
42
+ assert !@asset.icon?
43
+ end
44
+ should "not be editable" do
45
+ assert !@asset.editable?
46
+ end
47
+ should "not be able to read or write" do
48
+ assert_equal '', @asset.read
49
+ assert_equal false, @asset.write('test')
50
+ end
51
+ end
52
+
53
+ context "icon" do
54
+ setup do
55
+ @asset.update_attribute :asset_content_type, 'image/ico'
56
+ end
57
+ should "be an image" do
58
+ assert @asset.image?
59
+ end
60
+ should "be an icon" do
61
+ assert @asset.icon?
62
+ end
63
+ should "not be editable" do
64
+ assert !@asset.editable?
65
+ end
66
+ should "not be able to read or write" do
67
+ assert_equal '', @asset.read
68
+ assert_equal false, @asset.write('test')
69
+ end
70
+ end
71
+
72
+ context "javascript" do
73
+ setup do
74
+ @asset.update_attribute :asset_content_type, 'text/javascript'
75
+ setup_asset @asset.asset.path(:original)
76
+ end
77
+
78
+ should "not be an image" do
79
+ assert !@asset.image?
80
+ end
81
+ should "not be an icon" do
82
+ assert !@asset.icon?
83
+ end
84
+ should "be editable" do
85
+ assert @asset.editable?
86
+ end
87
+ should "be able to read or write" do
88
+ assert_equal true, @asset.write("alert('test')")
89
+ assert_equal "alert('test')\n", @asset.read
90
+ end
91
+ end
7
92
  end
8
93
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
1
+ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  class Cms::PageTest < ActiveSupport::TestCase
4
4
  def setup
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: liquid_cms
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 75
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
9
  - 0
9
- - 9
10
- version: 0.2.0.9
10
+ - 10
11
+ version: 0.2.0.10
11
12
  platform: ruby
12
13
  authors:
13
14
  - Andrew Kaspick
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2011-02-20 00:00:00 -06:00
20
+ date: 2011-02-25 00:00:00 -06:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -27,6 +28,7 @@ dependencies:
27
28
  requirements:
28
29
  - - ~>
29
30
  - !ruby/object:Gem::Version
31
+ hash: 9
30
32
  segments:
31
33
  - 2
32
34
  - 3
@@ -42,6 +44,7 @@ dependencies:
42
44
  requirements:
43
45
  - - ~>
44
46
  - !ruby/object:Gem::Version
47
+ hash: 1
45
48
  segments:
46
49
  - 2
47
50
  - 3
@@ -57,6 +60,7 @@ dependencies:
57
60
  requirements:
58
61
  - - ~>
59
62
  - !ruby/object:Gem::Version
63
+ hash: 21
60
64
  segments:
61
65
  - 1
62
66
  - 0
@@ -72,6 +76,7 @@ dependencies:
72
76
  requirements:
73
77
  - - "="
74
78
  - !ruby/object:Gem::Version
79
+ hash: 31
75
80
  segments:
76
81
  - 1
77
82
  - 0
@@ -87,6 +92,7 @@ dependencies:
87
92
  requirements:
88
93
  - - ~>
89
94
  - !ruby/object:Gem::Version
95
+ hash: 57
90
96
  segments:
91
97
  - 0
92
98
  - 9
@@ -102,6 +108,7 @@ dependencies:
102
108
  requirements:
103
109
  - - ~>
104
110
  - !ruby/object:Gem::Version
111
+ hash: 27
105
112
  segments:
106
113
  - 2
107
114
  - 3
@@ -117,6 +124,7 @@ dependencies:
117
124
  requirements:
118
125
  - - ">="
119
126
  - !ruby/object:Gem::Version
127
+ hash: 3
120
128
  segments:
121
129
  - 0
122
130
  version: "0"
@@ -130,6 +138,7 @@ dependencies:
130
138
  requirements:
131
139
  - - ~>
132
140
  - !ruby/object:Gem::Version
141
+ hash: 25
133
142
  segments:
134
143
  - 1
135
144
  - 2
@@ -145,6 +154,7 @@ dependencies:
145
154
  requirements:
146
155
  - - ~>
147
156
  - !ruby/object:Gem::Version
157
+ hash: 33
148
158
  segments:
149
159
  - 2
150
160
  - 10
@@ -152,6 +162,20 @@ dependencies:
152
162
  version: 2.10.3
153
163
  type: :development
154
164
  version_requirements: *id009
165
+ - !ruby/object:Gem::Dependency
166
+ name: mocha
167
+ prerelease: false
168
+ requirement: &id010 !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ hash: 3
174
+ segments:
175
+ - 0
176
+ version: "0"
177
+ type: :development
178
+ version_requirements: *id010
155
179
  description: " A context aware Rails CMS engine using the Liquid template library.\n Use the 0.3.x series for Rails 3 compatibility and the 0.2.x version for Rails 2 compatibility.\n"
156
180
  email:
157
181
  - andrew@redlinesoftware.com
@@ -1404,6 +1428,7 @@ files:
1404
1428
  - test/functional/main_controller_test.rb
1405
1429
  - test/functional/pages_controller_test.rb
1406
1430
  - test/integration/pages_test.rb
1431
+ - test/no_context_test_helper.rb
1407
1432
  - test/rails_app/Rakefile
1408
1433
  - test/rails_app/app/controllers/application_controller.rb
1409
1434
  - test/rails_app/app/controllers/cms/setup_controller.rb
@@ -1431,7 +1456,6 @@ files:
1431
1456
  - test/rails_app/config/locales/cms/en.yml
1432
1457
  - test/rails_app/config/locales/en.yml
1433
1458
  - test/rails_app/config/routes.rb
1434
- - test/rails_app/db/development.sqlite3
1435
1459
  - test/rails_app/db/migrate/20101018211856_create_liquid_cms_setup.rb
1436
1460
  - test/rails_app/db/seeds.rb
1437
1461
  - test/rails_app/public/404.html
@@ -1468,6 +1492,8 @@ files:
1468
1492
  - test/rails_app/script/runner
1469
1493
  - test/rails_app/script/server
1470
1494
  - test/test_helper.rb
1495
+ - test/test_helpers/asset_helpers.rb
1496
+ - test/test_helpers/cache_helper.rb
1471
1497
  - test/test_helpers/login_methods.rb
1472
1498
  - test/unit/asset_test.rb
1473
1499
  - test/unit/component_test.rb
@@ -1486,6 +1512,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
1486
1512
  requirements:
1487
1513
  - - ">="
1488
1514
  - !ruby/object:Gem::Version
1515
+ hash: 3
1489
1516
  segments:
1490
1517
  - 0
1491
1518
  version: "0"
@@ -1494,6 +1521,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1494
1521
  requirements:
1495
1522
  - - ">="
1496
1523
  - !ruby/object:Gem::Version
1524
+ hash: 23
1497
1525
  segments:
1498
1526
  - 1
1499
1527
  - 3
@@ -1518,6 +1546,7 @@ test_files:
1518
1546
  - test/functional/main_controller_test.rb
1519
1547
  - test/functional/pages_controller_test.rb
1520
1548
  - test/integration/pages_test.rb
1549
+ - test/no_context_test_helper.rb
1521
1550
  - test/rails_app/Rakefile
1522
1551
  - test/rails_app/app/controllers/application_controller.rb
1523
1552
  - test/rails_app/app/controllers/cms/setup_controller.rb
@@ -1545,7 +1574,6 @@ test_files:
1545
1574
  - test/rails_app/config/locales/cms/en.yml
1546
1575
  - test/rails_app/config/locales/en.yml
1547
1576
  - test/rails_app/config/routes.rb
1548
- - test/rails_app/db/development.sqlite3
1549
1577
  - test/rails_app/db/migrate/20101018211856_create_liquid_cms_setup.rb
1550
1578
  - test/rails_app/db/seeds.rb
1551
1579
  - test/rails_app/public/404.html
@@ -1582,6 +1610,8 @@ test_files:
1582
1610
  - test/rails_app/script/runner
1583
1611
  - test/rails_app/script/server
1584
1612
  - test/test_helper.rb
1613
+ - test/test_helpers/asset_helpers.rb
1614
+ - test/test_helpers/cache_helper.rb
1585
1615
  - test/test_helpers/login_methods.rb
1586
1616
  - test/unit/asset_test.rb
1587
1617
  - test/unit/component_test.rb
Binary file