Skip to content

Commit

Permalink
Fixed tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaspard committed Jan 30, 2012
1 parent 6c6d2e4 commit 9e2a7b2
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 64 deletions.
3 changes: 2 additions & 1 deletion History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Added 'remove_from_db' method to remove a site from the database.
* Fixed asset caching PLEASE FIX YOUR VHOST FILES: rake zena:create_vhost -s host='xxxxx'.
* Fixed deadlock_retry (a bug in the error message aborted the retry).
* Created 'spreadsheet' brick to ease xlsx and csv generation.
* Created 'spreadsheet' brick to ease xlsx and csv generation. <===== TODO: Document

* Minor changes
* Enabled Acl during document upload.
Expand All @@ -13,6 +13,7 @@
* Enabled 'alt_class' to work on multiple elements ([each]).
* Fixed ajax bugs with dom_ids in nested partials.
* Better Acl display, comments on relations.
* Support for 'to_date' on time object with proper timezone translation. <===== TODO: Document

== 1.1.3 2011-11-09

Expand Down
4 changes: 2 additions & 2 deletions bricks/acls/zena/test/integration/acl_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class AclIntegrationTest < Zena::Integration::TestCase
Zena::Db.execute "UPDATE acls SET format = 'csv' WHERE id = #{acls_id(:rap)}"
login(:hades)
# Create special mode template
secure(Template) { Template.create(:parent_id => nodes_id(:sky), :title => 'Node--csv', :text => 'foo;<r:title/>') }
secure(Template) { Template.create(:parent_id => nodes_id(:sky), :title => 'Node--csv', :text => %q{<r:spreadsheet><r:row><r:cell>foo</r:cell><r:cell eval='title'/></r:row></r:spreadsheet>}) }
post 'http://erebus.host/session', :login=>'demeter', :password=>'demeter'
end

Expand All @@ -94,7 +94,7 @@ class AclIntegrationTest < Zena::Integration::TestCase
should 'allow given mode' do
get "http://erebus.host/oo/project#{nodes_zip(:queen)}.csv"
assert_response :success
assert_equal 'foo;My Queen', response.body
assert_equal "foo;My Queen;\n", response.body
end
end # with fixed format

Expand Down
2 changes: 1 addition & 1 deletion bricks/pdf/lib/bricks/pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def render(options)

module ControllerMethods
def render_to_pdf(opts)
if params[:debug]
if opts[:debug]
template_path = template_url(opts)
result = {
:data => render_to_string(:file => template_path, :layout=>false),
Expand Down
22 changes: 17 additions & 5 deletions bricks/spreadsheet/lib/bricks/spreadsheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def initialize
end

def cell(value)
if value.kind_of?(Time)
tz = visitor.tz
value = tz.utc_to_local(value)
end
@cells << (value || '')
"#{value};"
end
Expand Down Expand Up @@ -50,7 +54,7 @@ def initialize
@sheets = []
end

def sheet(name)
def sheet(name = nil)
if name.kind_of?(Hash)
name = name[:name]
end
Expand Down Expand Up @@ -132,7 +136,7 @@ def render_to_xlsx(opts)
end

def render_spreadsheet(opts, type)
if params[:debug]
if opts[:debug]
type = :html
end
# Get zafu template (compile if needed)
Expand Down Expand Up @@ -215,7 +219,7 @@ def r_spreadsheet
expand_if("#{r} = @spreadsheet")
end

def r_sheet
def r_sheet(expand = true)
if doc = get_context_var('spreadsheet', 'doc')
s = get_var_name('spreadsheet', 'sheet')
if name = @params[:name]
Expand All @@ -228,14 +232,22 @@ def r_sheet
s,
:class => Bricks::Spreadsheet::Sheet
))
expand_with
if expand
expand_with
end
else
parser_error("Should only be called in a spreadsheet context.")
end
end

def r_row
if sheet = get_context_var('spreadsheet', 'sheet')
sheet = get_context_var('spreadsheet', 'sheet')
if !sheet
# Allow sheet to be omitted.
r_sheet(false)
sheet = get_context_var('spreadsheet', 'sheet')
end
if sheet
r = get_var_name('spreadsheet', 'row')
out "<% #{r} = #{sheet}.row %>"
set_context_var('spreadsheet', 'row', RubyLess::TypedString.new(
Expand Down
7 changes: 6 additions & 1 deletion bricks/spreadsheet/zena/test/zafu/spreadsheet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ default:
two_lines:
src: "<r:spreadsheet><r:sheet name='hep #{title}'><r:row><r:cell text='foo'/><r:cell eval='title'/></r:row><r:row><r:cell text='foo:#{title}'/><r:cell>blah</r:cell></r:row></r:sheet></r:spreadsheet>"
tem: "/if _zdoc = @spreadsheet.*_zsheet = _zdoc.sheet.\"hep #\{@node.*title.*/"
res: "foo;status title;\nfoo:status title;blah;\n"
res: "foo;status title;\nfoo:status title;blah;\n"

empty_cell:
src: "<r:spreadsheet><r:sheet name='hep #{title}'><r:row><r:cell text='foo'/><r:cell eval='title'/></r:row><r:row><r:cell text='foo:#{title}'/><r:cell/></r:row></r:sheet></r:spreadsheet>"
tem: "/if _zdoc = @spreadsheet.*_zsheet = _zdoc.sheet.\"hep #\{@node.*title.*/"
res: "foo;status title;\nfoo:status title;;\n"
5 changes: 1 addition & 4 deletions config/bricks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ test:
sphinx: OFF
worker: OFF
uv: OFF
spreadsheet:
switch: ON
activate_if:
gem: 'simple_xlsx'
spreadsheet: ON


development:
Expand Down
1 change: 1 addition & 0 deletions config/gems.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ httparty: '= 0.7.8'
open4:
daemons: # upload progress
gem_plugin: # upload progress
simple_xlsx_writer: # spreadsheet

querybuilder: '= 1.1.0'
yamltest: '= 0.7.0'
Expand Down
10 changes: 8 additions & 2 deletions lib/zena/test_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,18 @@ def test_compile
end

def test_render
if params[:format] then
if params[:format] and params[:format] != 'html' then
met = :"render_to_#{params[:format]}"
if respond_to?(met)
result = self.send(met, {:inline => @text})
render :text => result[:data]
headers.merge!(result[:type])
return
else
render :text => "Cannot handle #{params[:format]} rendering."
end
else
render :text => "Cannot handle #{params[:format]} rendering."
render :inline => @text
end
rescue => err
render :text => ([err.message] + err.backtrace[0..4]).join(" \n")
Expand Down Expand Up @@ -81,6 +82,11 @@ def set_context
params.delete(:text)
params.delete(:url)

tz = params.delete(:tz)
if tz
visitor.time_zone = tz
end

if controller = params.delete(:fake_controller)
# This is used when we need url rewriting.
case controller
Expand Down
25 changes: 25 additions & 0 deletions lib/zena/use/dates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,14 +293,39 @@ def strftime_tz(format, tz = nil)
rescue TZInfo::AmbiguousTime
''
end

def to_date_tz(tz = nil)
if tz.blank?
tz = visitor.tz
elsif tz.kind_of?(String)
tz = TZInfo::Timezone.get(tz)
end
tz.utc_to_local(self).to_date
rescue TZInfo::InvalidTimezoneIdentifier
''
rescue TZInfo::AmbiguousTime
''
end
end

module ZafuMethods
include RubyLess
safe_method_for Time, [:advance, {
:years => Number,
:months => Number,
:weeks => Number,
:days => Number,
:hours => Number,
:minutes => Number,
:seconds => Number}] => Time
safe_method_for Time, :to_i => {:class => Number, :pre_processor => true}
safe_method_for Time, :year => {:class => Number, :pre_processor => true}
safe_method_for Time, [:strftime, String] => {:class => String, :pre_processor => true, :method => 'strftime_tz'}
safe_method_for Time, [:strftime, String, String] => {:class => String, :pre_processor => true, :method => 'strftime_tz'}
safe_method_for Time, [:strftime, String, TZInfo::Timezone] => {:class => String, :pre_processor => true, :method => 'strftime_tz'}
safe_method_for Time, :to_date => {:class => Date, :pre_processor => true, :method => 'to_date_tz'}
safe_method_for Time, [:to_date, String] => {:class => Date, :pre_processor => true, :method => 'to_date_tz'}
safe_method_for Time, [:to_date, TZInfo::Timezone] => {:class => Date, :pre_processor => true, :method => 'to_date_tz'}
safe_method_for TZInfo::Timezone, :to_s => {:class => String, :pre_processor => true}

safe_method :date => :get_date
Expand Down
9 changes: 6 additions & 3 deletions lib/zena/use/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,13 @@ def get_options_for_select
nodes = finder[:method]
end

set_attr = ::RubyLess.translate(klass, @params[:attr] || 'id')
show_attr = ::RubyLess.translate(klass, @params[:show] || 'title')
set_attr, show_attr = nil
with_context(:node => node.move_to('r', klass)) do
set_attr = ::RubyLess.translate(self, @params[:attr] || 'id')
show_attr = ::RubyLess.translate(self, @params[:show] || 'title')
end

options_list = "[['','']] + (#{nodes} || []).map{|r| [r.#{show_attr}, r.#{set_attr}.to_s]}"
options_list = "[['','']] + (#{nodes} || []).map{|r| [#{show_attr}, #{set_attr}.to_s]}"
elsif values = @params[:values]
options_list = values.split(',').map(&:strip)

Expand Down
8 changes: 6 additions & 2 deletions lib/zena/use/rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ def render_and_cache(options={})
method = "render_to_#{opts[:format]}"
if params.keys.include?('debug')
opts[:cache] = false
params[:debug] = true
opts[:debug] = true
end

if respond_to?(method)
# Call custom rendering engine 'render_to_pdf' for example.
result = send(method, opts)
Expand Down Expand Up @@ -219,6 +220,8 @@ def cache_page(opts={})
# Return true if we can cache the current page
def caching_allowed(opts = {})
return false if current_site.authentication? || query_params != {}
# Cache even if authenticated (public content).
# Content viewed by anonymous user should be cached anyway.
opts[:authenticated] || visitor.is_anon?
end

Expand Down Expand Up @@ -302,6 +305,7 @@ def r_headers

def r_style
@markup.tag = 'style'
@markup.set_param(:type, 'text/css')
expand_with
end

Expand All @@ -318,4 +322,4 @@ def r_not_found
end # ZafuMethods
end # Rendering
end # Use
end # Zena
end # Zena
9 changes: 0 additions & 9 deletions lib/zena/use/zafu_safe_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,6 @@ def self.join_proc

safe_method_for Object, :blank? => Boolean

safe_method_for Time, [:advance, {
:years => Number,
:months => Number,
:weeks => Number,
:days => Number,
:hours => Number,
:minutes => Number,
:seconds => Number}] => Time
safe_method_for Time, :to_i => {:class => Number, :pre_processor => true}

safe_method_for Node, [:kind_of?, VirtualClass] =>
{:method => 'nil', :nil => true, :pre_processor => kind_of_proc}
Expand Down
20 changes: 13 additions & 7 deletions test/functional/nodes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class NodesControllerTest < Zena::Controller::TestCase

should 'insert cachestamp and render template' do
get_subject
#
#
assert_redirected_to "/en/page18_info.js?#{nodes(:projects).updated_at.to_i}"
get 'show', :path => subject[:path], :cachestamp => nodes(:projects).updated_at.to_i.to_s, :prefix => 'en'
assert_response :success
Expand Down Expand Up @@ -700,7 +700,7 @@ def test_should_cache_document_data_without_cachestamp
# cache info ok
get 'show', :prefix => 'en', :path => ["image#{node.zip}.jpg"], :cachestamp => node.updated_at.to_i
assert_response :success
assert File.exist?("#{SITES_ROOT}/test.host/public/en/image#{node.zip}.jpg")
assert File.exist?(make_cache_path("#{SITES_ROOT}/test.host/public/en/image#{node.zip}.jpg", node))
end
end
end
Expand Down Expand Up @@ -761,6 +761,10 @@ def test_ics_format_not_anon
end
end

def make_cache_path(file, node)
"#{file}.#{node.updated_at.to_i}"
end

def test_cache_css_auto_publish
test_site('zena')
Site.connection.execute "UPDATE sites set auto_publish = #{Zena::Db::TRUE}, redit_time = 7200 WHERE id = #{sites_id(:zena)}"
Expand All @@ -774,18 +778,20 @@ def test_cache_css_auto_publish
assert !File.exist?(filename)
get 'show', :prefix => 'en', :path => [name], :cachestamp => node.updated_at.to_i
assert_response :success
assert File.exist?(filename) # cached page created
assert_match %r[body \{ background: #eee; color:#444;], File.read(filename)
cache1 = make_cache_path(filename, node)
assert File.exist?(cache1) # cached page created
assert_match %r[body \{ background: #eee; color:#444;], File.read(cache1)
put 'save_text', :id => nodes_zip(:style_css), :node => {'text' => '/* empty */'}
node = assigns['node']
assert node.errors.empty?
assert_equal Zena::Status::Pub, node.version.status
assert_equal versions_id(:style_css_en), node.version.id # auto publish
assert !File.exist?(filename) # old cached page removed
assert !File.exist?(cache1) # old cached page removed
get 'show', :prefix => 'en', :path => [name], :cachestamp => node.updated_at.to_i
assert_response :success
assert File.exist?(filename) # cached page created again
assert_match %r[/\* empty \*/], File.read(filename)
cache2 = make_cache_path(filename, node)
assert File.exist?(cache2) # cached page created again
assert_match %r[/\* empty \*/], File.read(cache2)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/functional/virtual_classes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class VirtualClassesControllerTest < Zena::Controller::TestCase
post_subject
assert_response :success
diff = assigns(:diff)
assert_match(/<ins class="differ">Foo/, diff)
assert_match(/<ins class="differ">.*Foo/, diff)
end
end
end # importing virtual class definitions
Expand Down
2 changes: 1 addition & 1 deletion test/integration/query_node/dates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ date_tz_date:
# This date is translated to 2006-04-10 17:0 UTC
src: "nodes where created_at.date = #{date}"
sql: '/INTERVAL 1 DAY/'
res: "crocodiles"
res: "crocodiles"

0 comments on commit 9e2a7b2

Please sign in to comment.