require 'spec_helper' describe Writer::Fetcher::Microdata::PersonUser do it 'should have a proper initializer to a Writer' do user_stub = stub 'user' writer = Writer::Fetcher::Microdata::PersonUser.new user_stub writer.source.should == user_stub end describe '#hash' do before do @user_stub = stub 'user' end it 'should return the type' do final_hash = { "type" => [ "some type" ] } @user_stub.should_receive(:_type).and_return "some type" @user_stub.should_receive(:attributes).and_return stub :[] => nil writer = Writer::Fetcher::Microdata::PersonUser.new @user_stub writer.hash.should include final_hash end describe 'properties hash' do before do @user_stub.should_receive :_type end it 'should include the additionalType' do @properties_hash = { "additionalType" => [ "http://getfetcher.net/Item" ] } @user_stub.should_receive(:attributes).and_return :additionalType => "http://getfetcher.net/Item" end it 'should include the Item#id' do @properties_hash = { "Item#id" => [ 234525 ] } @user_stub.should_receive(:attributes).and_return :id => 234525 end it 'should include the name' do @properties_hash = { "name" => [ "Marcus" ] } @user_stub.should_receive(:attributes).and_return :name => "Marcus" end it 'should include the dateRegistered' do @properties_hash = { "User#dateRegistered" => [ 456468768 ] } @user_stub.should_receive(:attributes).and_return :dateRegistered => 456468768 end it 'should include the description' do @properties_hash = { "description" => [ 456468768 ] } @user_stub.should_receive(:attributes).and_return :description => 456468768 end it 'should include the url' do @properties_hash = { "url" => [ 456468768 ] } @user_stub.should_receive(:attributes).and_return :url => 456468768 end after :each do writer = Writer::Fetcher::Microdata::PersonUser.new @user_stub writer.hash["properties"].should include @properties_hash end end end describe "#hash innecesary data" do it 'should not put dateRegistered on the data if data registered is nil' do @properties_hash = { "User#dateRegistered" => [nil] } aux_stub = stub "aux stub" aux_stub.stub(:[]) do |symbol| if symbol == :dateRegistered nil else symbol.to_s end end @nil_user_stub.should_receive(:_type).and_return "some type" @nil_user_stub.should_receive(:attributes).and_return aux_stub writer = Writer::Fetcher::Microdata::PersonUser.new @nil_user_stub writer.hash["properties"].should_not include @properties_hash end it 'should not put description on the data if data registered is nil' do @properties_hash = { "description" => [nil] } aux_stub = stub "aux stub" aux_stub.stub(:[]) do |symbol| if symbol == :description nil else symbol.to_s end end @nil_user_stub.should_receive(:_type).and_return "some type" @nil_user_stub.should_receive(:attributes).and_return aux_stub writer = Writer::Fetcher::Microdata::PersonUser.new @nil_user_stub writer.hash["properties"].should_not include @properties_hash end it 'should not put url on the data if data registered is nil' do @properties_hash = { "url" => [nil] } aux_stub = stub "aux stub" aux_stub.stub(:[]) do |symbol| if symbol == :url nil else symbol.to_s end end @nil_user_stub.should_receive(:_type).and_return "some type" @nil_user_stub.should_receive(:attributes).and_return aux_stub writer = Writer::Fetcher::Microdata::PersonUser.new @nil_user_stub writer.hash["properties"].should_not include @properties_hash end end end