# encoding: utf-8 # # This file is part of the mbrao gem. Copyright (C) 2013 and above Shogun . # Licensed under the MIT license, which can be found at http://www.opensource.org/licenses/mit-license.php. # require "spec_helper" describe Mbrao::Author do describe ".create" do it "creates a author from a non-hash" do expect(Mbrao::Author).to receive(:new).with("NAME") Mbrao::Author.create("NAME") expect(Mbrao::Author).to receive(:new).with(nil) Mbrao::Author.create(nil) expect(Mbrao::Author).to receive(:new).with([]) Mbrao::Author.create([]) expect(Mbrao::Author).to receive(:new).with(["NAME"]) Mbrao::Author.create(["NAME"]) end it "creates a author from a hash" do expect(Mbrao::Author).to receive(:new).with("NAME", "EMAIL", "WEBSITE", "IMAGE", {"other" => "OTHER"}, "UID") Mbrao::Author.create({name: "NAME", email: "EMAIL", website: "WEBSITE", image: "IMAGE", other: "OTHER", uid: "UID"}) end end describe "#initialize" do it "create a new object" do reference = Mbrao::Author.new("NAME", "name@example.com", "http://example.com", "http://example.com/image.jpg", {a: {b: :c}}) expect(reference.name).to eq("NAME") expect(reference.email).to eq("name@example.com") expect(reference.website).to eq("http://example.com") expect(reference.image).to eq("http://example.com/image.jpg") expect(reference.metadata).to eq({"a" => {"b" => :c}}) end it "make sure that email is valid" do reference = Mbrao::Author.new("NAME", "INVALID", "http://example.com", "http://example.com/image.jpg", {a: {b: :c}}) expect(reference.email).to be_nil end it "make sure that website is a valid URL" do reference = Mbrao::Author.new("NAME", "name@example.com", "INVALID", "http://example.com/image.jpg", {a: {b: :c}}) expect(reference.website).to be_nil end it "make sure that image is a valid URL" do reference = Mbrao::Author.new("NAME", "name@example.com", "http://example.com", "INVALID", {a: {b: :c}}) expect(reference.image).to be_nil end it "make sure that hash is a recursively a HashWithIndifferentAccess" do reference = Mbrao::Author.new("NAME", "name@example.com", "http://example.com", "http://example.com/image.jpg", {a: {b: :c}}) expect(reference.metadata).to be_a(HashWithIndifferentAccess) expect(reference.metadata["a"]).to be_a(HashWithIndifferentAccess) end end end