# encoding: utf-8 describe ServiceObjects::Helpers::Messages do let(:messages_class) { ServiceObjects::Message } let(:test_class) { Class.new } before { ServiceObjects::Test = test_class } before { test_class.include described_class } after { ServiceObjects.send :remove_const, :Test } subject { test_class.new } describe "#translate" do let(:scope) { %w(activemodel messages models service_objects/test) } let(:traslation) { I18n.t(:text, scope: scope, name: "name") } it "translates symbols in the service's scope" do expect(subject.translate(:text, name: "name")).to eq traslation end it "doesn't translate strings" do expect(subject.translate("text")).to eq "text" end it "converts non-symbolic argument to string" do expect(subject.translate nil).to eq "" expect(subject.translate 1).to eq "1" end end # #translate describe "#messages" do it "returns an array" do expect(subject.messages).to be_kind_of Array end end # #messages describe "#add_message" do let(:message) { subject.messages.first } it "adds a new message to the #messages" do subject.add_message text: "foo", type: "bar", priority: 5, baz: 0 expect(message).to be_kind_of messages_class expect(message.type).to eq "bar" expect(message.text).to eq "foo" expect(message.priority).to eq 5.0 end it "translates a symbol" do subject.add_message text: :foo, type: :bar, priority: 5, baz: 0 translation = subject.translate :foo, baz: 0 expect(message.text).to eq translation end end # #add_message end # ServiceObjects::Helpers::Messages