Sha256: a37972678deabd967655ec20d4340a7dc9d7fc1bb8e100ba7e50d5e33cab2464

Contents?: true

Size: 1.98 KB

Versions: 15

Compression:

Stored size: 1.98 KB

Contents

# Copyright (c) 2008-2013 Michael Dvorkin and contributors.
#
# Fat Free CRM is freely distributable under the terms of MIT license.
# See MIT-LICENSE file or http://www.opensource.org/licenses/mit-license.php
#------------------------------------------------------------------------------
# == Schema Information
#
# Table name: fields
#
#  id             :integer         not null, primary key
#  type           :string(255)
#  field_group_id :integer
#  position       :integer
#  name           :string(64)
#  label          :string(128)
#  hint           :string(255)
#  placeholder    :string(255)
#  as             :string(32)
#  collection     :text
#  disabled       :boolean
#  required       :boolean
#  maxlength      :integer
#  created_at     :datetime
#  updated_at     :datetime
#

require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')

describe Field do
  it "should create a new instance given valid attributes" do
    Field.create!(
      name:      'skype_address',
      label:     'Skype address',
      as:        'string',
      maxlength: 220,
      position:  10
    )
  end

  it "should return a list of field types" do
    expect(Field.field_types['string']).to eq('klass' => 'CustomField', 'type' => 'string')
  end

  it "should return a hash of input options" do
    expect(Field.new.input_options).to be_a(Hash)
  end

  it "should be able to display a empty multi_select value" do
    field = Field.new(
      label: "Availability",
      name:  "availability"
    )
    object = double('Object')

    #  as  |  value  |  expected
    [["check_boxes", [1, 2, 3],               "1, 2<br />3"],
     %w(checkbox 0 no),
     ["checkbox",    1,                       "yes"],
     ["date",        DateTime.new(2011, 4, 19), DateTime.new(2011, 4, 19).strftime(I18n.t("date.formats.mmddyy"))]].each do |as, value, expected|
      field.as = as
      allow(object).to receive(field.name).and_return(value)
      expect(field.render_value(object)).to eq(expected)
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
fat_free_crm-0.14.2 spec/models/fields/field_spec.rb
fat_free_crm-0.15.2 spec/models/fields/field_spec.rb
fat_free_crm-0.16.4 spec/models/fields/field_spec.rb
fat_free_crm-0.14.1 spec/models/fields/field_spec.rb
fat_free_crm-0.15.1 spec/models/fields/field_spec.rb
fat_free_crm-0.16.3 spec/models/fields/field_spec.rb
fat_free_crm-0.16.2 spec/models/fields/field_spec.rb
fat_free_crm-0.16.1 spec/models/fields/field_spec.rb
fat_free_crm-0.16.0 spec/models/fields/field_spec.rb
fat_free_crm-0.15.0 spec/models/fields/field_spec.rb
fat_free_crm-0.15.0.beta.2 spec/models/fields/field_spec.rb
fat_free_crm-0.15.0.beta spec/models/fields/field_spec.rb
fat_free_crm-0.14.0 spec/models/fields/field_spec.rb
reduced_fat_crm-0.15.0.beta spec/models/fields/field_spec.rb
reduced_fat_crm-0.14.0 spec/models/fields/field_spec.rb