Sha256: 8ba7b16efeee291beabe545715f554661846ff2faf564336b0b3e32efd554dfe

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# encoding: utf-8
require "spec_helper"

module Hexx
  describe Helpers::Messages do

    before  { class Test; include Helpers::Messages; end }
    subject { Test.new }
    after   { Hexx.send :remove_const, :Test }

    describe "#t" do

      let(:scope)      { %w(activemodel messages models hexx/test) }
      let(:traslation) { I18n.t(:text, scope: scope, name: "name") }

      it "translates symbols in the service scope" do
        expect(subject.t(:text, name: "name")).to eq traslation
      end

      it "doesn't translate the string" do
        expect(subject.t("text")).to eq "text"
      end
    end

    describe "#messages" do

      it "returns an array" do
        expect(subject.messages).to be_kind_of Array
      end
    end

    describe "#messages=" do

      it "sets #messages" do
        expect { subject.messages = ["text"] }
          .to change { subject.messages }.to ["text"]
      end
    end

    describe "#add_message" do

      before        { subject.add_message :info, :text }
      let(:message) { subject.messages.first }

      it "adds a new message" do
        expect(message).to be_kind_of Hexx::Message
        expect(message.type).to eq "info"
      end

      it "translates a symbol" do
        translation = subject.t :text
        expect(message.text).to eq translation
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hexx-7.0.0 spec/hexx/helpers/messages_spec.rb