Sha256: cdff8a6c8081bf7ff8ac97aa64601a9e350093f435aa24b44ab35a5d3e94f0a7

Contents?: true

Size: 997 Bytes

Versions: 4

Compression:

Stored size: 997 Bytes

Contents

require "spec_helper"

describe Formulaic::Label do
  it "returns the string if there are no translations and it can not human_attribute_name the class" do
    expect(label(nil, "My label")).to eq "My label"
  end

  it "returns human_attribute_name if available" do
    expect(label(:user, :first_name)).to eq "First name"
  end

  it "uses a translation if available" do
    I18n.backend.store_translations(:en, { simple_form: { labels: { user: { name: "Translated" } } } } )

    expect(label(:user, :name)).to eq("Translated")
  end

  it "should leave cases alone" do
    expect(label(:user, "Work URL")).to eq "Work URL"
  end

  it "uses the attribute when the model is not found" do
    expect(label(:student, "Course selection")).to eq "Course selection"
  end

  class User
    def self.human_attribute_name(attribute)
      attribute.to_s.humanize
    end
  end

  def label(model_name, attribute, action = :new)
    Formulaic::Label.new(model_name, attribute, action).to_str
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
formulaic-0.3.0 spec/formulaic/label_spec.rb
formulaic-0.2.0 spec/formulaic/label_spec.rb
formulaic-0.1.4 spec/formulaic/label_spec.rb
formulaic-0.1.3 spec/formulaic/label_spec.rb