Skip to content

Commit

Permalink
added #virtual? commodity method, fixed a bug where virtual methods w…
Browse files Browse the repository at this point in the history
…ould get searched on in list views
  • Loading branch information
bbenezech committed Oct 26, 2011
1 parent c713d77 commit 2ce7b0f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/views/rails_admin/main/export.html.haml
Expand Up @@ -13,7 +13,7 @@
%ul.inputs-list
- visible_fields.select{ |f| !f.association? || f.association[:polymorphic] }.each do |field|
%li
- list = field.type != :virtual ? 'only' : 'methods'
- list = field.virtual? ? 'methods' : 'only'
- if field.association? && field.association[:polymorphic]
%label{:for => "schema_#{list}_#{field.method_name}"}
= check_box_tag "schema[#{list}][]", field.method_name, true, { :id => "schema_#{list}_#{field.method_name}" }
Expand Down
12 changes: 9 additions & 3 deletions lib/rails_admin/config/fields/base.rb
Expand Up @@ -45,6 +45,10 @@ def column_css_class(*args, &block)
css_class
end
end

def virtual?
properties.blank?
end

register_instance_option(:column_width) do
self.class.instance_variable_get("@column_width")
Expand All @@ -61,13 +65,13 @@ def column_css_class(*args, &block)
register_instance_option(:truncated?) do
ActiveSupport::Deprecation.warn("'#{self.name}.truncated?' is deprecated, use '#{self.name}.pretty_value' instead", caller)
end

register_instance_option(:sortable) do
true
!virtual?
end

register_instance_option(:searchable) do
true
!virtual?
end

register_instance_option(:queryable?) do
Expand Down Expand Up @@ -263,6 +267,8 @@ def dom_id
def method_name
name
end


end
end
end
Expand Down
26 changes: 26 additions & 0 deletions spec/requests/config/rails_admin_config_spec.rb
Expand Up @@ -98,6 +98,32 @@
should have_css(".born_on_field")
end
end

describe "searchable and sortable" do
it 'should be false if column is virtual, true otherwise' do
RailsAdmin.config League do
field :virtual_column
field :name
end
@league = FactoryGirl.create :league
RailsAdmin.config('League').export.fields.find{ |f| f.name == :virtual_column }.sortable.should == false
RailsAdmin.config('League').export.fields.find{ |f| f.name == :virtual_column }.searchable.should == false
RailsAdmin.config('League').export.fields.find{ |f| f.name == :name }.sortable.should == true
RailsAdmin.config('League').export.fields.find{ |f| f.name == :name }.searchable.should == true
end
end

describe "virtual?" do
it 'should be true if column has no properties, false otherwise' do
RailsAdmin.config League do
field :virtual_column
field :name
end
@league = FactoryGirl.create :league
RailsAdmin.config('League').export.fields.find{ |f| f.name == :virtual_column }.virtual?.should == true
RailsAdmin.config('League').export.fields.find{ |f| f.name == :name }.virtual?.should == false
end
end

describe "search operator" do
let(:abstract_model) { RailsAdmin::AbstractModel.new('player') }
Expand Down

0 comments on commit 2ce7b0f

Please sign in to comment.