Sha256: a2bfab0e108edc917e9bb8aecba2d2f0e3dc45f895233da78af2ef365a3895f5

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require "spec_helper"

describe DataMapper::Property::ParseFile do
  subject { property }

  let(:property) { Article.properties[:attachment] }

  describe "#dump" do
    subject { property.dump value }

    let(:value) { { "name" => "xx.txt", "url" => "http://a.cn/xx.txt" } }

    it { should eq(value.merge("__type" => "File")) }

    context "when value is nil" do
      let(:value) { nil }

      it { should be_nil }
    end

    context "when value is io" do
      let(:value) { StringIO.new "xx" }
      
      before { value.stub(original_filename: "xx.txt") }
      before { DataMapper::Parse::Resource.any_instance.stub(post: {"name" => "x", "url" => "y"}) }

      it { should be_has_key("__type") }
      it { should be_has_key("name") }
      it { should be_has_key("url") }
    end
  end

  describe "#load" do
    subject { property.load value }

    let(:value) { { "__type" => "File", "name" => "a.png", "url" => "http://a.cn/a.png" } }

    it { should eq(value) }

    context "when value is nil" do
      let(:value) { nil }

      it { should be_nil }
    end
  end

  describe "#valid?" do
    subject { property.valid? value }

    let(:value) { { "__type" => "File", "name" => "a.png", "url" => "http://a.cn/a.png" } }

    it { should be_true }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dm-parse-0.2.1 spec/parse_file_spec.rb