Sha256: 5d427fd5bfea786f00ef45ec0fd933f596bb92f299a5e760a2e3c67648689004

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

require "sequel-fixture"
require "fast"

describe Sequel::Fixture do
  # This should go in a dependency, pending refactoring TODO
  describe "#simplify" do
    context "when receiving a multidimensional hash containing a field with raw and processed" do
      it "should convert it in a simple hash using the processed value as replacement" do
        base_hash = {
          :name => "Jane",
          :band => "Witherspoons",
          :pass => {
            :raw => "secret",
            :processed => "53oih7fhjdgj3f8="
          },
          :email => {
            :raw => "Jane@gmail.com ",
            :processed => "jane@gmail.com"
          }
        }
        
        fix = Sequel::Fixture.new
        simplified = fix.simplify(base_hash)
        simplified.should == {
          :name => "Jane",
          :band => "Witherspoons",
          :pass => "53oih7fhjdgj3f8=",
          :email => "jane@gmail.com"
        }
      end
    end
    
    context "the multidimensional array is missing the processed part of the field" do
      it "should raise an exception" do
        base_hash = {
          :name => "Jane",
          :pass => {
            :raw => "secret",
            :not_processed => "53oih7fhjdgj3f8="
          },
          :email => {
            :raw => "Jane@gmail.com ",
            :processed => "jane@gmail.com"
          }
        }
        
        fix = Sequel::Fixture.new
        expect { fix.simplify(base_hash)
        }.to raise_error Sequel::Fixture::MissingProcessedValueError, 
          "The processed value to insert into the db is missing from the field 'pass', aborting"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sequel-fixture-2.0.1 spec/sequel/util_spec.rb
sequel-fixture-2.0.0 spec/sequel/util_spec.rb