Skip to content

Commit

Permalink
Fixed field indexing on new object (draft). Added user_id / version.u…
Browse files Browse the repository at this point in the history
…ser_id safe methods. Using <p> tag in checkbox.
  • Loading branch information
gaspard committed May 25, 2011
1 parent ede2bf7 commit 0aac692
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def self.author_proc
:traductions => ['Version'], :discussion => 'Discussion'

# we use safe_method because the columns can be null, but the values are never null
safe_method :kpath => String, :user_zip => Number,
safe_method :kpath => String, :user_zip => Number, :user_id => Number,
:parent_zip => Number, :project_zip => Number, :section_zip => Number,
:ref_lang => String,
:position => Number, :rgroup_id => Number,
Expand Down
2 changes: 1 addition & 1 deletion app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Version < ActiveRecord::Base
include RubyLess
safe_attribute :created_at, :updated_at, :publish_from, :status, :lang
safe_method :node => 'Node', :id => {:class => Number, :method => 'number'},
:number => Number, :user => 'User',
:number => Number, :user => 'User', :user_id => Number, :user_zip => {:class => Number, :method => 'user_id'},
:author => Node.author_proc

# We need to include Property::Base so that we can read the properties that
Expand Down
2 changes: 1 addition & 1 deletion lib/zena/use/ajax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def need_ajax?(each_block)
# FIXME: HACK
# This dom_id detection code is crap but it fixes the drop in each bug.
def get_dom_id(target)
if dom_id = target.markup.dyn_params[:id]
if dom_id = target.markup.dyn_params[:id] || target.markup.params[:id]
if dom_id =~ /^<%=\s+(.*?)\s+%>$/
dom_id = $1
else
Expand Down
5 changes: 4 additions & 1 deletion lib/zena/use/field_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ def self.included(base)
end

def property_field_index
if version.status == Zena::Status[:pub]
# Better rule
if new_record? ||
version.status == Zena::Status[:pub] ||
versions.count == 1
super
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/zena/use/forms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def make_checkbox(node, opts)
current_values = relation_proxy.other_ids
res << "<input type='hidden' name='node[#{role}_ids][]' value=''/>"
values.each do |value|
res << ("<span><input type='checkbox' name='node[#{role}_ids][]' value='#{value.zip}'" +
res << ("<p><input type='checkbox' name='node[#{role}_ids][]' value='#{value.zip}'" +
(current_values.include?(value.id) ? " checked='checked'/> " : '/> ') +
"<span>#{value.prop[attribute]}</span>")
"<span>#{value.prop[attribute]}</span></p>")
end
end
res.join('')
Expand Down
28 changes: 28 additions & 0 deletions test/unit/zena/use/field_index_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'test_helper'

class FieldIndexTest < Zena::Unit::TestCase
context 'A visitor with write access' do
setup do
login(:lion)
end

context 'creating a node' do

context 'that is not published' do
# Post has 'date' as field index
subject do
secure(Node) { Node.create_node(
:title => 'Piksel',
:parent_id => nodes_zip(:cleanWater),
:class => 'Post',
:date => '2011-05-25'
)}
end

should 'write index in field' do
assert_equal '2011-05-25', subject.idx_datetime1.strftime('%Y-%m-%d')
end
end # that is not published
end # creating a node
end # A visitor with write access
end
4 changes: 2 additions & 2 deletions test/unit/zena/use/ml_index_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class MLIndexTest < Zena::Unit::TestCase
col = Column.create(:role_id => buz.id, :ptype => 'string', :name => 'foo', :index => 'string')
assert !col.new_record?
end

teardown do
# avoid test leakage
VirtualClass.expire_cache!
end

subject do
secure(Node) { Node.create_node(
:class => 'Buz',
Expand Down
1 change: 1 addition & 0 deletions zena.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2207,6 +2207,7 @@ Gem::Specification.new do |s|
"test/unit/zena/use/dates_string_methods_test.rb",
"test/unit/zena/use/dates_test.rb",
"test/unit/zena/use/dates_view_methods_test.rb",
"test/unit/zena/use/field_index_test.rb",
"test/unit/zena/use/fulltext_test.rb",
"test/unit/zena/use/html_tags_test.rb",
"test/unit/zena/use/i18n_test.rb",
Expand Down

0 comments on commit 0aac692

Please sign in to comment.