Browse files

refactored css_class/column_width

added tests, corrected doc and moved it to wiki
  • Loading branch information...
1 parent fb2a834 commit 92fa07b4b7fa07ddf3319d2ce11eaf52aa34f32c @bbenezech bbenezech committed Nov 15, 2011
View
35 README.md
@@ -658,41 +658,6 @@ options are defined for a single field, `strftime_format` has precedence over
[Rails Internationalization API](http://edgeguides.rubyonrails.org/i18n.html#adding-date-time-formats)
and [Rails I18n repository](https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale).
-**Fields - Column CSS class**
-
-By default each column has a CSS class set according to field's data type. You
-can customize this by:
-
- RailsAdmin.config do |config|
- config.model Team do
- list do
- field :name
- field :created_at do
- css_class "customClass"
- end
- end
- end
- end
-
-This would render the "created at" field's header and body columns with a CSS class named
-"customClass".
-
-**Fields - Column width**
-
-By default columns' widths are calculated from certain pre-defined,
-data-type-specific pixel values. If you want to ensure a minimum width for a
-column, you can:
-
- RailsAdmin.config do |config|
- config.model Team do
- list do
- field :name do
- column_width 200
- end
- field :created_at
- end
- end
- end
### Create and update views
View
2 app/helpers/rails_admin/form_builder.rb
@@ -19,7 +19,7 @@ def fieldset_for fieldset
end
def field_wrapper_for field
- @template.content_tag(:div, :class => "clearfix field #{'error' if field.errors.present?}", :id => field.dom_id + '_field') do
+ @template.content_tag(:div, :class => "clearfix field #{field.type_css_class} #{field.css_class} #{'error' if field.errors.present?}", :id => field.dom_id + '_field') do
label(field.method_name, field.label) +
input_for(field)
end
View
101 app/helpers/rails_admin/main_helper.rb
@@ -9,92 +9,23 @@ def get_indicator(percent)
return "warning" if percent < 84 # < 1/3 of max
return "important" # > 1/3 of max
end
-
- def get_column_set(properties)
- sets = calculate_width(properties)
- current_set ||= params[:set].to_i
-
- raise NotFound if sets.size <= current_set
-
- selected_set = sets[current_set][:p]
- style, other = justify_properties(sets, current_set)
-
- return style, other, selected_set
- end
-
- private
-
- def calculate_width(properties)
- # local variables
- total = 0
- set = []
-
- # variables used in loop
- partial_total = 0
- temp = []
-
- # loop through properties
- properties.each do |property|
- # get width for the current property
- width = property.column_width || 120
-
- # if properties that were gathered so far have the width
- # over 697 make a set for them
- if partial_total + width >= RailsAdmin::Config.total_columns_width
- set << {:p => temp, :size => partial_total}
- partial_total = 0
- temp = []
- end
-
- # continue to add properties to set
- temp << property
- partial_total += width
- total += width
+
+ def get_column_sets(properties)
+ sets = []
+ property_index = 0
+ set_index = 0
+
+ while (property_index < properties.length)
+ current_set_width = 0
+ begin
+ sets[set_index] ||= []
+ sets[set_index] << properties[property_index]
+ current_set_width += (properties[property_index].column_width || 120)
+ property_index += 1
+ end while (current_set_width < RailsAdmin::Config.total_columns_width) && (property_index < properties.length)
+ set_index += 1
end
-
- # add final set to returned value
- set << {:p => temp, :size => partial_total}
-
- return set
+ sets
end
-
- def justify_properties(sets, current_set)
- total = 697
- style = {}
-
- properties = sets[current_set][:p]
- # calculate the maximum distance
- total = sets.size == 1 ? 784 : 744
- max_sets = sets.size-2
- total = current_set.between?(1, max_sets) ? 704 : total
- column_offset = total-sets[current_set][:size]
- per_property = properties.size != 0 ? column_offset / properties.size : 0
- offset = column_offset - per_property * properties.size
-
- properties.each do |property|
- property_type = property.column_css_class
- if width = property.column_width
- style[property_type] ||= {:size => 0, :occ => 0, :width => 0}
- style[property_type][:size] += per_property
- style[property_type][:occ] += 1
- style[property_type][:width] = width + style[property_type][:size] / style[property_type][:occ]
- end
- end
-
- other = []
-
- if total == 784
- other = ["left", "right"]
- elsif total == 744
- if current_set == 0
- other = ["left"]
- else
- other = ["right"]
- end
- end
-
- return style, other
- end
-
end
end
View
28 app/views/rails_admin/main/index.html.haml
@@ -6,7 +6,10 @@
properties = @model_config.list.with(:view => self, :object => @abstract_model.model.new).visible_fields
# columns paginate
@filterable_fields = @model_config.list.fields.select(&:filterable?)
- @style, @other, properties = get_column_set(properties)
+ sets = get_column_sets(properties)
+ properties = sets[params[:set].to_i]
+ other_left = ((params[:set].to_i - 1) >= 0) && sets[params[:set].to_i - 1].present?
+ other_right = sets[params[:set].to_i + 1].present?
@index = 0
@ordered_filters = (params[:filters] || @model_config.list.filters).inject({}) { |memo, filter|
field_name = filter.is_a?(Array) ? filter.first : filter
@@ -44,8 +47,9 @@
#list
%style
- - @style.each do |key, value|
- \.grid thead #{key} { width: #{value[:width] }px; }
+ - properties.select{ |p| p.column_width.present? }.each do |property|
+ = "#list th.#{property.css_class} { width: #{property.column_width}px; min-width: #{property.column_width}px; }"
+ = "#list td.#{property.css_class} { max-width: #{property.column_width}px; }"
= form_tag(index_path(params.except(*%w[page filters query])), :method => :post, :remote => true) do
.row
.span12
@@ -65,28 +69,30 @@
%th.first.shrink
- if can_bulk_action
%input.checkbox.toggle{:type => "checkbox"}
- %th.other.left.shrink{ :style => "#{'display: none' if @other.include?("left")}" }...
+ - if other_left
+ %th.other.left.shrink= "..."
- properties.each do |property|
- selected = (sort == property.name.to_s)
- if property.sortable
- sort_location = index_path params.except('page').merge(:sort => property.name, :sort_reverse => (selected && sort_reverse != 'true') ? 'true' : 'false')
- sort_direction = selected ? (sort_reverse == 'true' ? "headerSortUp" : "headerSortDown") : nil
- %th{:class => "#{property.sortable && "header" || nil} #{property.sortable && sort_direction ? sort_direction : nil} #{property.css_class}", :'data-link' => (property.sortable && sort_location)}= property.label
- %th.other.right.shrink{ :style => "#{'display: none' if @other.include?("right")}" }...
+ %th{:class => "#{property.sortable && "header" || nil} #{property.sortable && sort_direction ? sort_direction : nil} #{property.css_class} #{property.type_css_class}", :'data-link' => (property.sortable && sort_location)}= property.label
+ - if other_right
+ %th.other.right.shrink= "..."
%th.last.shrink
%tbody
- @objects.each do |object|
%tr
%td.select.action
- if can_bulk_action
= check_box_tag "bulk_ids[]", object.id, false, :id => "bulk_ids_#{object.id}", :class => "checkbox"
- - other_left = index_path(params.merge(:set => (params[:set].to_i - 1)))
- %td.other.left{ :style => "#{'display: none' if @other.include?("left")}" }= link_to "...", other_left, :remote => true
+ - if other_left_link ||= other_left && index_path(params.merge(:set => (params[:set].to_i - 1)))
+ %td.other.left= link_to "...", other_left_link, :remote => true
- properties.map{ |property| property.bind(:object, object) }.each do |property|
- value = property.pretty_value
- %td{:class => property.css_class, :title => strip_tags(value)}= value
- - other_right = index_path(params.merge(:set => (params[:set].to_i + 1)))
- %td.other.right{ :style => "#{'display: none' if @other.include?("right")}" }= link_to "...", other_right, :remote => true
+ %td{:class => "#{property.css_class} #{property.type_css_class}", :title => strip_tags(value)}= value
+ - if other_right_link ||= other_right && index_path(params.merge(:set => (params[:set].to_i + 1)))
+ %td.other.right= link_to "...", other_right_link, :remote => true
%td.last.links
%ul.inline= render :partial => 'rails_admin/main/object_links', :locals => { :add_active_class => false, :model_name => params[:model_name], :object => object }
- unless params[:all]
View
2 app/views/rails_admin/main/show.html.haml
@@ -9,6 +9,6 @@
%dl
- fields.each_with_index do |field, index|
- if (value = values[index]) || !RailsAdmin::config.compact_show_view
- %dt.label{:class => "#{field.name}_field"}= field.label
+ %dt.label{:class => "#{field.type_css_class} #{field.css_class}"}= field.label
%dd
%pre.prettyprint= value || ' - '
View
21 lib/rails_admin/config/fields/base.rb
@@ -14,8 +14,7 @@ class Base < RailsAdmin::Config::Base
attr_accessor :defined, :order
def self.inherited(klass)
- klass.instance_variable_set("@css_class", klass.name.to_s.demodulize.camelcase(:lower))
- klass.instance_variable_set("@view_helper", :text_field)
+ klass.instance_variable_set("@view_helper", :text_field)
end
include RailsAdmin::Config::Hideable
@@ -35,23 +34,19 @@ def initialize(parent, name, properties)
end
register_instance_option(:css_class) do
- self.class.instance_variable_get("@css_class")
+ "#{self.name}_field"
end
-
- def column_css_class(*args, &block)
- if !args[0].nil? || block
- @css_class = args[0].nil? ? block : args[0]
- else
- css_class
- end
+
+ def type_css_class
+ "#{type}_type"
end
def virtual?
properties.blank?
end
register_instance_option(:column_width) do
- self.class.instance_variable_get("@column_width")
+ nil
end
register_instance_option(:read_only) do
@@ -146,9 +141,7 @@ def virtual?
end
register_instance_option(:html_attributes) do
- {
- :class => css_class
- }
+ {}
end
# Accessor for field's label.
View
4 lib/rails_admin/config/fields/types/integer.rb
@@ -10,10 +10,6 @@ class Integer < RailsAdmin::Config::Fields::Base
@view_helper = :number_field
- register_instance_option(:css_class) do
- serial? ? "id" : "integer"
- end
-
register_instance_option(:sort_reverse?) do
serial?
end
View
2 lib/rails_admin/config/fields/types/polymorphic_association.rb
@@ -8,8 +8,6 @@ class PolymorphicAssociation < RailsAdmin::Config::Fields::Types::BelongsToAssoc
# Register field type for the type loader
RailsAdmin::Config::Fields::Types::register(self)
- @column_width = 250
-
register_instance_option(:partial) do
:form_polymorphic_association
end
View
1 lib/rails_admin/config/fields/types/string.rb
@@ -12,7 +12,6 @@ class String < RailsAdmin::Config::Fields::Base
register_instance_option(:html_attributes) do
{
- :class => css_class,
:maxlength => length,
:size => [50, length.to_i].min
}
View
1 lib/rails_admin/config/fields/types/text.rb
@@ -23,7 +23,6 @@ class Text < RailsAdmin::Config::Fields::Base
register_instance_option(:html_attributes) do
{
- :class => css_class,
:cols => "48",
:rows => "3"
}
View
15 spec/requests/config/edit/rails_admin_config_edit_spec.rb
@@ -34,6 +34,13 @@
@field_test.restricted_field.should == "I'm allowed to do that as :custom_role only"
end
end
+
+ describe "css hooks" do
+ it "should be present" do
+ visit new_path(:model_name => "team")
+ should have_selector("#team_division_id_field.field.belongs_to_association_type.division_field")
+ end
+ end
describe "field groupings" do
@@ -681,7 +688,7 @@ def color_enum
end
end
visit new_path(:model_name => "team")
- should have_selector("select.enum")
+ should have_selector(".enum_type select")
should have_content("green")
Team.send(:remove_method, :color_enum) # Reset
end
@@ -700,7 +707,7 @@ def color_list
end
end
visit new_path(:model_name => "team")
- should have_selector("select.enum")
+ should have_selector(".enum_type select")
should have_content("green")
Team.send(:remove_method, :color_list) # Reset
end
@@ -722,7 +729,7 @@ def color_list
end
end
visit new_path(:model_name => "team")
- should have_selector("select.enum")
+ should have_selector(".enum_type select")
should have_no_content("green")
should have_content("yellow")
Team.send(:remove_method, :color_list) # Reset
@@ -738,7 +745,7 @@ def color_list
end
end
visit new_path(:model_name => "team")
- should have_selector("input.color")
+ should have_selector(".color_type input")
end
end
end
View
190 spec/requests/config/list/rails_admin_config_list_spec.rb
@@ -4,6 +4,16 @@
subject { page }
+ describe "css hooks" do
+ it "should be present" do
+ FactoryGirl.create :team
+ visit index_path(:model_name => "team")
+ should have_selector("th.header.string_type.name_field")
+ should have_selector("td.string_type.name_field")
+ end
+ end
+
+
describe "number of items per page" do
before(:each) do
@@ -59,10 +69,10 @@
it "should show all by default" do
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Id")
- should have_selector("th:nth-child(4)", :text => "Created at")
- should have_selector("th:nth-child(5)", :text => "Updated at")
- should have_selector("th:nth-child(6)", :text => "His Name")
+ find("th:nth-child(2)").should have_content("Id")
+ find("th:nth-child(3)").should have_content("Created at")
+ find("th:nth-child(4)").should have_content("Updated at")
+ find("th:nth-child(5)").should have_content("His Name")
end
it "should hide some fields on demand with a block" do
@@ -74,8 +84,8 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Id")
- should have_selector("th:nth-child(4)", :text => "His Name")
+ find("th:nth-child(2)").should have_content("Id")
+ find("th:nth-child(3)").should have_content("His Name")
end
it "should hide some fields on demand with fields list" do
@@ -85,8 +95,8 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Id")
- should have_selector("th:nth-child(4)", :text => "His Name")
+ find("th:nth-child(2)").should have_content("Id")
+ find("th:nth-child(3)").should have_content("His Name")
end
it "should add some fields on demand with a block" do
@@ -98,8 +108,8 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Id")
- should have_selector("th:nth-child(4)", :text => "His Name")
+ find("th:nth-child(2)").should have_content("Id")
+ find("th:nth-child(3)").should have_content("His Name")
end
it "should show some fields on demand with fields list, respect ordering and configure them" do
@@ -113,8 +123,9 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Modified His Name")
- should have_selector("th:nth-child(4)", :text => "Modified Id")
+
+ find("th:nth-child(2)").should have_content("Modified His Name")
+ find("th:nth-child(3)").should have_content("Modified Id")
end
it "should show all fields if asked" do
@@ -126,10 +137,11 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Id")
- should have_selector("th:nth-child(4)", :text => "Created at")
- should have_selector("th:nth-child(5)", :text => "Updated at")
- should have_selector("th:nth-child(6)", :text => "His Name")
+
+ find("th:nth-child(2)").should have_content("Id")
+ find("th:nth-child(3)").should have_content("Created at")
+ find("th:nth-child(4)").should have_content("Updated at")
+ find("th:nth-child(5)").should have_content("His Name")
end
it "should appear in order defined" do
@@ -142,10 +154,11 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Updated at")
- should have_selector("th:nth-child(4)", :text => "His Name")
- should have_selector("th:nth-child(5)", :text => "Id")
- should have_selector("th:nth-child(6)", :text => "Created at")
+
+ find("th:nth-child(2)").should have_content("Updated at")
+ find("th:nth-child(3)").should have_content("His Name")
+ find("th:nth-child(4)").should have_content("Id")
+ find("th:nth-child(5)").should have_content("Created at")
end
it "should only list the defined fields if some fields are defined" do
@@ -156,10 +169,9 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Id")
- should have_selector("th:nth-child(4)", :text => "His Name")
- should have_no_selector("th:nth-child(5)", :text => "Created at")
- should have_no_selector("th:nth-child(6)", :text => "Updated at")
+ find("th:nth-child(2)").should have_content("Id")
+ find("th:nth-child(3)").should have_content("His Name")
+ should have_no_selector("th:nth-child(4).header")
end
it "should delegate the label option to the ActiveModel API" do
@@ -169,7 +181,7 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "His Name")
+ find("th:nth-child(2)").should have_content("His Name")
end
it "should be renameable" do
@@ -182,8 +194,8 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Identifier")
- should have_selector("th:nth-child(4)", :text => "His Name")
+ find("th:nth-child(2)").should have_content("Identifier")
+ find("th:nth-child(3)").should have_content("His Name")
end
it "should be renameable by type" do
@@ -195,10 +207,10 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Id")
- should have_selector("th:nth-child(4)", :text => "Created at (datetime)")
- should have_selector("th:nth-child(5)", :text => "Updated at (datetime)")
- should have_selector("th:nth-child(6)", :text => "His Name")
+ find("th:nth-child(2)").should have_content("Id")
+ find("th:nth-child(3)").should have_content("Created at (datetime)")
+ find("th:nth-child(4)").should have_content("Updated at (datetime)")
+ find("th:nth-child(5)").should have_content("His Name")
end
it "should be globally renameable by type" do
@@ -210,18 +222,18 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Id")
- should have_selector("th:nth-child(4)", :text => "Created at (datetime)")
- should have_selector("th:nth-child(5)", :text => "Updated at (datetime)")
- should have_selector("th:nth-child(6)", :text => "His Name")
+ find("th:nth-child(2)").should have_content("Id")
+ find("th:nth-child(3)").should have_content("Created at (datetime)")
+ find("th:nth-child(4)").should have_content("Updated at (datetime)")
+ find("th:nth-child(5)").should have_content("His Name")
end
it "should be sortable by default" do
visit index_path(:model_name => "fan")
+ should have_selector("th:nth-child(2).header")
should have_selector("th:nth-child(3).header")
should have_selector("th:nth-child(4).header")
should have_selector("th:nth-child(5).header")
- should have_selector("th:nth-child(6).header")
end
it "should have option to disable sortability" do
@@ -234,8 +246,8 @@
end
end
visit index_path(:model_name => "fan")
- should have_no_selector("th:nth-child(3).header")
- should have_selector("th:nth-child(4).header")
+ should have_no_selector("th:nth-child(2).header")
+ should have_selector("th:nth-child(3).header")
end
it "should have option to disable sortability by type" do
@@ -251,10 +263,10 @@
end
end
visit index_path(:model_name => "fan")
+ should have_selector("th:nth-child(2).header")
should have_selector("th:nth-child(3).header")
- should have_selector("th:nth-child(4).header")
+ should have_no_selector("th:nth-child(4).header")
should have_no_selector("th:nth-child(5).header")
- should have_no_selector("th:nth-child(6).header")
end
it "should have option to disable sortability by type globally" do
@@ -270,10 +282,10 @@
end
end
visit index_path(:model_name => "fan")
+ should have_selector("th:nth-child(2).header")
should have_selector("th:nth-child(3).header")
- should have_selector("th:nth-child(4).header")
+ should have_no_selector("th:nth-child(4).header")
should have_no_selector("th:nth-child(5).header")
- should have_no_selector("th:nth-child(6).header")
end
it "should have option to hide fields by type" do
@@ -285,10 +297,10 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Id")
- should have_selector("th:nth-child(4)", :text => "His Name")
- should have_no_selector("th:nth-child(5)", :text => "Created at")
- should have_no_selector("th:nth-child(6)", :text => "Updated at")
+ should have_selector("th:nth-child(2)", :text => "Id")
+ should have_selector("th:nth-child(3)", :text => "His Name")
+ should have_no_selector("th:nth-child(4)", :text => "Created at")
+ should have_no_selector("th:nth-child(5)", :text => "Updated at")
end
it "should have option to hide fields by type globally" do
@@ -300,63 +312,10 @@
end
end
visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3)", :text => "Id")
- should have_selector("th:nth-child(4)", :text => "His Name")
- should have_no_selector("th:nth-child(5)", :text => "Created at")
- should have_no_selector("th:nth-child(6)", :text => "Updated at")
- end
-
- it "should have option to customize css class name" do
- RailsAdmin.config Fan do
- list do
- field :id do
- css_class "customClass"
- end
- field :name
- end
- end
- @fans = 2.times.map { FactoryGirl.create :fan }
- visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(3).customClass")
- should have_selector("th:nth-child(4).string")
- should have_selector("td:nth-child(3).customClass")
- should have_selector("td:nth-child(4).string")
- end
-
- it "should have option to customize css class name by type" do
- RailsAdmin.config Fan do
- list do
- fields_of_type :datetime do
- css_class "customClass"
- end
- end
- end
- @fans = 2.times.map { FactoryGirl.create :fan }
- visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(4).customClass")
- should have_selector("th:nth-child(5).customClass")
- should have_selector("th:nth-child(6).string")
- should have_selector("td:nth-child(4).customClass")
- should have_selector("td:nth-child(5).customClass")
- should have_selector("td:nth-child(6).string")
- end
-
- it "should have option to customize css class name by type globally" do
- RailsAdmin::Config.models do
- list do
- fields_of_type :datetime do
- css_class "customClass"
- end
- end
- end
- @fans = 2.times.map { FactoryGirl.create :fan }
- visit index_path(:model_name => "fan")
- should have_selector("th:nth-child(4).customClass")
- should have_selector("th:nth-child(5).customClass")
- should have_selector("th:nth-child(6).string")
- should have_selector("td:nth-child(4).customClass")
- should have_selector("td:nth-child(5).customClass")
- should have_selector("td:nth-child(6).string")
+ should have_selector("th:nth-child(2)", :text => "Id")
+ should have_selector("th:nth-child(3)", :text => "His Name")
+ should have_no_selector("th:nth-child(4)", :text => "Created at")
+ should have_no_selector("th:nth-child(5)", :text => "Updated at")
end
it "should have option to customize column width" do
@@ -372,7 +331,8 @@
end
@fans = 2.times.map { FactoryGirl.create :fan }
visit index_path(:model_name => "fan")
- find('style').should have_content('.grid thead')
+ find('style').should have_content('#list th.id_field')
+ find('style').should have_content('#list td.id_field')
end
it "should have option to customize output formatting" do
@@ -390,8 +350,8 @@
end
@fans = 2.times.map { FactoryGirl.create :fan }
visit index_path(:model_name => "fan")
- should have_selector("tbody tr:nth-child(1) td:nth-child(4)", :text => @fans[1].name.upcase)
- should have_selector("tbody tr:nth-child(2) td:nth-child(4)", :text => @fans[0].name.upcase)
+ find('tbody tr:nth-child(1) td:nth-child(3)').should have_content(@fans[1].name.upcase)
+ find('tbody tr:nth-child(2) td:nth-child(3)').should have_content(@fans[0].name.upcase)
end
it "should have a simple option to customize output formatting of date fields" do
@@ -407,7 +367,7 @@
end
@fans = 2.times.map { FactoryGirl.create :fan }
visit index_path(:model_name => "fan")
- should have_selector("tbody tr:nth-child(1) td:nth-child(5)", :text => /\d{2} \w{3} \d{1,2}:\d{1,2}/)
+ should have_selector("tbody tr:nth-child(1) td:nth-child(4)", :text => /\d{2} \w{3} \d{1,2}:\d{1,2}/)
end
it "should have option to customize output formatting of date fields" do
@@ -423,7 +383,7 @@
end
@fans = 2.times.map { FactoryGirl.create :fan }
visit index_path(:model_name => "fan")
- should have_selector("tbody tr:nth-child(1) td:nth-child(5)", :text => /\d{4}-\d{2}-\d{2}/)
+ should have_selector("tbody tr:nth-child(1) td:nth-child(4)", :text => /\d{4}-\d{2}-\d{2}/)
end
it "should allow addition of virtual fields (object methods)" do
@@ -437,7 +397,7 @@
@team = FactoryGirl.create :team
@players = 2.times.map { FactoryGirl.create :player, :team => @team }
visit index_path(:model_name => "team")
- should have_selector("tbody tr:nth-child(1) td:nth-child(5)", :text => @players.collect(&:name).join(", "))
+ find('tbody tr:nth-child(1) td:nth-child(4)').should have_content(@players.collect(&:name).join(", "))
end
end
@@ -475,7 +435,7 @@
end
visit index_path(:model_name => "player")
player_names_by_date.reverse.each_with_index do |name, i|
- should have_selector("tbody tr:nth-child(#{i + 1})", :text => name)
+ find("tbody tr:nth-child(#{i + 1})").should have_content(name)
end
end
@@ -488,7 +448,7 @@
end
visit index_path(:model_name => "player")
player_names_by_date.reverse.each_with_index do |name, i|
- should have_selector("tbody tr:nth-child(#{i + 1})", :text => name)
+ find("tbody tr:nth-child(#{i + 1})").should have_content(name)
end
end
@@ -511,12 +471,12 @@
visit index_path(:model_name => "league")
league_names_by_date.reverse.each_with_index do |name, i|
- should have_selector("tbody tr:nth-child(#{i + 1})", :text => name)
+ find("tbody tr:nth-child(#{i + 1})").should have_content(name)
end
visit index_path(:model_name => "player")
@players.sort_by{|p| p[:id]}.map{|p| p[:name]}.reverse.each_with_index do |name, i|
- should have_selector("tbody tr:nth-child(#{i + 1})", :text => name)
+ find("tbody tr:nth-child(#{i + 1})").should have_content(name)
end
end
end
@@ -529,7 +489,7 @@
end
visit index_path(:model_name => "player")
player_names_by_date.reverse.each_with_index do |name, i|
- should have_selector("tbody tr:nth-child(#{i + 1})", :text => name)
+ find("tbody tr:nth-child(#{i + 1})").should have_content(name)
end
end
@@ -542,7 +502,7 @@
end
visit index_path(:model_name => "player")
player_names_by_date.each_with_index do |name, i|
- should have_selector("tbody tr:nth-child(#{i + 1})", :text => name)
+ find("tbody tr:nth-child(#{i + 1})").should have_content(name)
end
end
end
View
16 spec/requests/config/rails_admin_config_spec.rb
@@ -78,6 +78,22 @@
RailsAdmin.config('League').with(:object => @league).object_label.should == "League '#{@league.name}'"
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
+ css_class "custom"
+ end
+ field :name
+ end
+ end
+ RailsAdmin.config('Team').list.fields.find{|f| f.name == :division}.css_class.should == "custom" # custom
+ RailsAdmin.config('Team').list.fields.find{|f| f.name == :division}.type_css_class.should == "belongs_to_association_type" # type css class, non-customizable
+ RailsAdmin.config('Team').list.fields.find{|f| f.name == :name}.css_class.should == "name_field" # default
+ end
+ end
describe "compact_show_view" do
View
7 spec/requests/config/show/rails_admin_config_show_spec.rb
@@ -13,6 +13,13 @@ def do_request
visit show_path(:model_name => "team", :id => team.id)
end
+ describe "css hooks" do
+ it "should be present" do
+ do_request
+ should have_selector("dt.name_field.string_type")
+ end
+ end
+
describe "field groupings" do
it "should be hideable" do
RailsAdmin.config Team do
View
2 spec/requests/rails_admin_spec.rb
@@ -47,7 +47,7 @@
end
it "should work like belongs to associations in the list view" do
- visit index_path(:model_name => "comment", :set => "1")
+ visit index_path(:model_name => "comment")
should have_content(@team.name)
end

0 comments on commit 92fa07b

Please sign in to comment.