liquid_cms 0.3.0.7 → 0.3.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,12 @@
1
+ == 0.3.0.8
2
+
3
+ * Enhancements
4
+ * Allow text based assets to be editable inline.
5
+
6
+ * Bug Fixes
7
+ * Fix errors with editing and listing uploaded components.
8
+ * Fix translation issues making hint text html_safe.
9
+
1
10
  == 0.3.0.2
2
11
 
3
12
  Updated codemirror to 0.9
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: .
10
10
  specs:
11
- liquid_cms (0.3.0.6)
11
+ liquid_cms (0.3.0.7)
12
12
  bundler (>= 1.0.0)
13
13
  formatize
14
14
  paperclip (~> 2.3.1)
@@ -68,6 +68,7 @@ GEM
68
68
  mime-types
69
69
  treetop (>= 1.4.5)
70
70
  mime-types (1.16)
71
+ mocha (0.9.12)
71
72
  paperclip (2.3.4)
72
73
  activerecord
73
74
  activesupport
@@ -110,6 +111,7 @@ DEPENDENCIES
110
111
  factory_girl_rails
111
112
  formatize
112
113
  liquid_cms!
114
+ mocha
113
115
  paperclip (~> 2.3.1)
114
116
  rails (~> 3.0.0)
115
117
  rubyzip (~> 0.9.1)
@@ -62,6 +62,12 @@ In order to expose data in your application in the templates, liquid filters, dr
62
62
 
63
63
  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.
64
64
 
65
+ = Upgrading
66
+
67
+ 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.
68
+
69
+ 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.
70
+
65
71
  = Contribution
66
72
 
67
73
  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
 
@@ -50,7 +50,7 @@ class Cms::ComponentsController < Cms::MainController
50
50
 
51
51
  protected
52
52
  def load_component_path
53
- @path = params[:url].first
53
+ @path = params[:url]
54
54
  @path = CGI::unescape(@path) if @path.present?
55
55
  end
56
56
  end
@@ -10,26 +10,26 @@ module Cms::ComponentsHelper
10
10
  end
11
11
 
12
12
  def list_files(path, hidden = false)
13
- ''.tap do |html|
14
- html += hidden ? %[<ul class="tree" style="display:none">] : %[<ul class="tree">]
15
- for file in Dir[File.expand_path(path)+"/*"] do
16
- html += "<li>"
17
- if File.directory?(file)
18
- html += cms_icon('folder.png', :class => 'folder') + ' ' + component_delete_link(file) + ' '
19
- html += content_tag(:span, File.basename(file), :title => Cms::Component.component_path(@context, file))
20
- html += list_files(file, true)
13
+ html = ''
14
+ html += hidden ? %[<ul class="tree" style="display:none">] : %[<ul class="tree">]
15
+ for file in Dir[File.expand_path(path)+"/*"] do
16
+ html += "<li>"
17
+ if File.directory?(file)
18
+ html += cms_icon('folder.png', :class => 'folder') + ' ' + component_delete_link(file) + ' '
19
+ html += content_tag(:span, File.basename(file), :title => Cms::Component.component_path(@context, file))
20
+ html += list_files(file, true)
21
+ else
22
+ html += file_type_icon(File.basename(file)) + ' '
23
+ html += component_delete_link(file) + ' '
24
+ if Cms::Component.editable?(file)
25
+ html += component_edit_link(file)
21
26
  else
22
- html += file_type_icon(File.basename(file)) + ' '
23
- html += component_delete_link(file) + ' '
24
- if Cms::Component.editable?(file)
25
- html += component_edit_link(file)
26
- else
27
- html += content_tag(:span, truncate(File.basename(file), :length => 15), :title => Cms::Component.component_path(@context, file))
28
- end
27
+ html += content_tag(:span, truncate(File.basename(file), :length => 15), :title => Cms::Component.component_path(@context, file))
29
28
  end
30
- html += "</li>"
31
29
  end
32
- html += "</ul>"
33
- end.html_safe
30
+ html += "</li>"
31
+ end
32
+ html += "</ul>"
33
+ html.html_safe
34
34
  end
35
35
  end
@@ -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
@@ -98,7 +98,7 @@ module Cms
98
98
 
99
99
  def content=(text)
100
100
  write_attribute :content, text
101
- self.is_layout_page = !(text =~ /\{\{\s?content_for_layout\s?\}\}/).nil?
101
+ self.is_layout_page = !(text =~ /\{\{\s?content_for_layout\s?\}\}/).blank?
102
102
  end
103
103
 
104
104
  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').html_safe %></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').html_safe %></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').html_safe, :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,8 +4,14 @@ 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(@template.t('simple_form.buttons.cancel'), :back, :class => 'cancel')
8
8
  end.html_safe
9
9
  end
10
10
  end
11
11
  end
12
+
13
+ module SimpleForm::Components::Hints
14
+ def hint_text
15
+ @hint_text ||= (options[:hint] || translate(:hints)).html_safe
16
+ end
17
+ 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 {
@@ -6,7 +6,7 @@ module Cms
6
6
  mattr_reader :context_class
7
7
  def self.context_class=(klass)
8
8
  @@context_class = klass
9
- return if klass.nil?
9
+ return if klass.nil? || ENV['NO_CONTEXT'] == 'true'
10
10
 
11
11
  eval(klass.to_s).extend Cms::ContextAssociation
12
12
 
@@ -1,3 +1,3 @@
1
1
  module Cms
2
- VERSION = "0.3.0.7"
2
+ VERSION = "0.3.0.8"
3
3
  end
@@ -29,6 +29,7 @@ Gem::Specification.new do |s|
29
29
  s.add_development_dependency 'sqlite3-ruby'
30
30
  s.add_development_dependency 'factory_girl', "~> 1.3.0"
31
31
  s.add_development_dependency 'shoulda', "~> 2.10.3"
32
+ s.add_development_dependency 'mocha'
32
33
 
33
34
  test_files = `git ls-files test/`.split("\n")
34
35
  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,81 +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 => fixture_file_upload(File.join(ASSET_PATH, 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 => fixture_file_upload(File.join('assets', File.basename(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
87
+
88
+ should "modify the contents of an non-editable asset file" do
89
+ asset = Factory(:js_asset, :context => @company)
90
+
91
+ asset_file = asset_file(asset.asset_file_name)
92
+ setup_asset asset_file
56
93
 
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)
94
+ Cms::Asset.any_instance.stubs(:asset => stub(:path => asset_file))
95
+ Cms::Asset.any_instance.expects(:write).with('new content').returns(true)
60
96
 
61
- xhr :delete, :destroy, :id => asset
62
- assert_response :success
63
- assert_nil @company.assets.find_by_id(asset.id)
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
- ASSET_PATH = 'assets'
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
79
115
 
80
- def asset_path
81
- File.join(TestConfig.paperclip_test_root, ASSET_PATH)
82
- end
116
+ should "destroy asset via XHR :DELETE" do
117
+ assert_not_nil @company.assets.find_by_id(@asset.id)
83
118
 
84
- def asset_file(file_name)
85
- File.join(asset_path, file_name)
119
+ xhr :delete, :destroy, :id => @asset
120
+ assert_response :success
121
+ assert_nil @company.assets.find_by_id(@asset.id)
122
+ end
123
+ end
86
124
  end
87
125
  end
@@ -0,0 +1,3 @@
1
+ ENV['NO_CONTEXT'] = 'true'
2
+
3
+ require File.dirname(__FILE__) + '/test_helper'
@@ -10,6 +10,12 @@ require "rails_app/config/environment"
10
10
  require 'rails/test_help'
11
11
  require 'ostruct'
12
12
 
13
+ if ENV['NO_CONTEXT'] == 'true'
14
+ Cms.setup do |config|
15
+ config.context_class = nil
16
+ end
17
+ end
18
+
13
19
  ActiveRecord::Migration.verbose = false
14
20
  ActiveRecord::Base.logger = Logger.new(nil)
15
21
  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
  include ActionDispatch::TestProcess
@@ -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
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
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 3
8
8
  - 0
9
- - 7
10
- version: 0.3.0.7
9
+ - 8
10
+ version: 0.3.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Andrew Kaspick
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-02-20 00:00:00 -06:00
19
+ date: 2011-02-25 00:00:00 -06:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -165,6 +165,19 @@ dependencies:
165
165
  version: 2.10.3
166
166
  type: :development
167
167
  version_requirements: *id010
168
+ - !ruby/object:Gem::Dependency
169
+ name: mocha
170
+ prerelease: false
171
+ requirement: &id011 !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ segments:
177
+ - 0
178
+ version: "0"
179
+ type: :development
180
+ version_requirements: *id011
168
181
  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"
169
182
  email:
170
183
  - andrew@redlinesoftware.com
@@ -1417,6 +1430,7 @@ files:
1417
1430
  - test/functional/main_controller_test.rb
1418
1431
  - test/functional/pages_controller_test.rb
1419
1432
  - test/integration/pages_test.rb
1433
+ - test/no_context_test_helper.rb
1420
1434
  - test/rails_app/Gemfile
1421
1435
  - test/rails_app/Gemfile.lock
1422
1436
  - test/rails_app/Rakefile
@@ -1464,6 +1478,8 @@ files:
1464
1478
  - test/rails_app/public/robots.txt
1465
1479
  - test/rails_app/script/rails
1466
1480
  - test/test_helper.rb
1481
+ - test/test_helpers/asset_helpers.rb
1482
+ - test/test_helpers/cache_helper.rb
1467
1483
  - test/test_helpers/login_methods.rb
1468
1484
  - test/unit/asset_test.rb
1469
1485
  - test/unit/component_test.rb
@@ -1514,6 +1530,7 @@ test_files:
1514
1530
  - test/functional/main_controller_test.rb
1515
1531
  - test/functional/pages_controller_test.rb
1516
1532
  - test/integration/pages_test.rb
1533
+ - test/no_context_test_helper.rb
1517
1534
  - test/rails_app/Gemfile
1518
1535
  - test/rails_app/Gemfile.lock
1519
1536
  - test/rails_app/Rakefile
@@ -1561,6 +1578,8 @@ test_files:
1561
1578
  - test/rails_app/public/robots.txt
1562
1579
  - test/rails_app/script/rails
1563
1580
  - test/test_helper.rb
1581
+ - test/test_helpers/asset_helpers.rb
1582
+ - test/test_helpers/cache_helper.rb
1564
1583
  - test/test_helpers/login_methods.rb
1565
1584
  - test/unit/asset_test.rb
1566
1585
  - test/unit/component_test.rb