Sha256: 6ea174ba5d9eb366cb31ae4dc5afb076bc126733c872627844b80386d8c3bb01
Contents?: true
Size: 1.78 KB
Versions: 11
Compression:
Stored size: 1.78 KB
Contents
# frozen_string_literal: true require "spec_helper" RSpec.describe MrCommon::Country, type: :model do context ".all" do it "returns an array" do expect(MrCommon::Country.all).to be_a_kind_of Array end it "each element is a [name, code] pair" do element = MrCommon::Country.all.first expect(element[0]).to eq "Afghanistan" expect(element[1]).to eq "AF" end it "moves elements to the front of the list" do element = MrCommon::Country.all([:us]).first expect(element[0]).to eq "United States" expect(element[1]).to eq "US" end it "moves elements to the front of the list in given order" do gb_element = MrCommon::Country.all([:us, :gb]).first expect(gb_element[0]).to eq "United States" expect(gb_element[1]).to eq "US" us_element = MrCommon::Country.all([:us, :gb]).second expect(us_element[0]).to eq "United Kingdom" expect(us_element[1]).to eq "GB" end end context ".names" do it "returns an array" do expect(MrCommon::Country.names).to be_a_kind_of Array end it "each element is a country's name" do element = MrCommon::Country.names.first expect(element).to eq "Afghanistan" end end context ".codes" do it "returns an array" do expect(MrCommon::Country.codes).to be_a_kind_of Array end it "each element is a country's alpha2 code" do element = MrCommon::Country.codes.first expect(element).to eq "AD" expect(element.length).to eq 2 end end context ".name_for" do it "returns a country name for the given code" do expect(MrCommon::Country.name_for("AF")).to eq "Afghanistan" end it "also accepts lowercase" do expect(MrCommon::Country.name_for("af")).to eq "Afghanistan" end end end
Version data entries
11 entries across 11 versions & 1 rubygems