spec/unit/config/fields/base_spec.rb in rails_admin-0.0.5 vs spec/unit/config/fields/base_spec.rb in rails_admin-0.1.0
- old
+ new
@@ -1,9 +1,20 @@
require 'spec_helper'
describe RailsAdmin::Config::Fields::Base do
+ describe "#required" do
+ it "should read the :on => :create/:update validate option" do
+ RailsAdmin.config Ball do
+ field 'color'
+ end
+
+ RailsAdmin.config('Ball').fields.first.with(:object => Ball.new).should be_required
+ RailsAdmin.config('Ball').fields.first.with(:object => FactoryGirl.create(:ball)).should_not be_required
+ end
+ end
+
describe "#name" do
it 'should be normalized to Symbol' do
RailsAdmin.config Team do
field 'name'
end
@@ -90,10 +101,25 @@
it 'should be nil by default' do
RailsAdmin.config('Team').list.fields.find{|f| f.name == :name}.default_value.should be_nil
end
end
+ describe "#hint" do
+ it "should be user customizable" do
+ RailsAdmin.config Team do
+ list do
+ field :division do
+ hint "Great Division"
+ end
+ field :name
+ end
+ end
+ RailsAdmin.config('Team').list.fields.find{|f| f.name == :division}.hint.should == "Great Division" # custom
+ RailsAdmin.config('Team').list.fields.find{|f| f.name == :name}.hint.should == "" # default
+ end
+ end
+
describe "#css_class" do
it "should have a default and be user customizable" do
RailsAdmin.config Team do
list do
field :division do
@@ -341,8 +367,38 @@
end
RailsAdmin.config(FieldVisibilityTest).base.fields.select{|f| f.visible? }.map(&:name).should =~ [:_id, :created_at, :created_on, :deleted_at, :deleted_on, :id, :name, :updated_at, :updated_on]
RailsAdmin.config(FieldVisibilityTest).list.fields.select{|f| f.visible? }.map(&:name).should =~ [:_id, :created_at, :created_on, :deleted_at, :deleted_on, :id, :name, :updated_at, :updated_on]
RailsAdmin.config(FieldVisibilityTest).edit.fields.select{|f| f.visible? }.map(&:name).should =~ [:name]
RailsAdmin.config(FieldVisibilityTest).show.fields.select{|f| f.visible? }.map(&:name).should =~ [:name]
+ end
+ end
+
+ describe '#editable?' do
+ before do
+ Moped.logger.stub!(:debug) if defined?(Moped)
+ end
+
+ it 'should yell for non attr_accessible fields if config.yell_for_non_accessible_fields is true' do
+ RailsAdmin.config do |config|
+ config.yell_for_non_accessible_fields = true
+ config.model FieldTest do
+ field :protected_field
+ end
+ end
+ Rails.logger.should_receive(:debug).with {|msg| msg =~ /Please add 'attr_accessible :protected_field'/ }
+ editable = RailsAdmin.config(FieldTest).field(:protected_field).with(:object => FactoryGirl.create(:field_test), :view => double(:controller => double(:_attr_accessible_role => :default))).editable?
+ editable.should == false
+ end
+
+ it 'should not yell for non attr_accessible fields if config.yell_for_non_accessible_fields is false' do
+ RailsAdmin.config do |config|
+ config.yell_for_non_accessible_fields = false
+ config.model FieldTest do
+ field :protected_field
+ end
+ end
+ Rails.logger.should_not_receive(:debug).with {|msg| msg =~ /Please add 'attr_accessible :protected_field'/ }
+ editable = RailsAdmin.config(FieldTest).field(:protected_field).with(:object => FactoryGirl.create(:field_test), :view => double(:controller => double(:_attr_accessible_role => :default))).editable?
+ editable.should == false
end
end
end