Sha256: 698eff3c16a5920794fa82988fb0acfdbf43e7106d9776368235eef2def1d658
Contents?: true
Size: 1.66 KB
Versions: 6
Compression:
Stored size: 1.66 KB
Contents
require 'spec_helper' require 'fixtures/user' describe CsvShaper::Header do before(:each) do config = double(:config, options: { header_inflector: :humanize }) allow(CsvShaper::Shaper).to receive(:config) { config } end it "should accept and store a list of symbols" do header = CsvShaper::Header.new(:name, :age, :location) expect(header.columns).to eq [:name, :age, :location] end it "should accept a Model and store it's attributes" do header = CsvShaper::Header.new(User) expect(header.columns).to eq [:name, :age, :gender] end it "should accept a block with columns and mappings" do header = CsvShaper::Header.new do |csv| csv.columns :name, :age, :foo csv.mappings name: 'User name' end expect(header.columns).to eq [:name, :age, :foo] expect(header.mapped_columns).to eq ['User name', 'Age', 'Foo'] end it "should titleize column names according to the chosen inflector" do header = CsvShaper::Header.new do |csv| csv.columns :first_name, :full_age csv.inflector :titleize end expect(header.columns).to eq [:first_name, :full_age] expect(header.mapped_columns).to eq ['First Name', 'Full Age'] end it "should merge columns with a union join" do header = CsvShaper::Header.new(:name, :age, :location) header.columns :age, :gender expect(header.columns).to eq [:name, :age, :location, :gender] end it "should merge mappings" do header = CsvShaper::Header.new do |csv| csv.columns :name, :age, :foo csv.mappings name: 'User name' csv.mappings foo: 'Bar' end expect(header.mapped_columns).to eq ['User name', 'Age', 'Bar'] end end
Version data entries
6 entries across 6 versions & 1 rubygems