Skip to content

Commit

Permalink
Fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
dohzya committed Oct 2, 2013
1 parent f60b5cd commit 7a05632
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 29 deletions.
11 changes: 8 additions & 3 deletions spec/fragments_spec.rb
Expand Up @@ -198,7 +198,7 @@
end

it "returns a HTML element whose content is the value" do
Nokogiri::XML(@color.as_html).child.content.should == @hex_value
Nokogiri::XML(@color.as_html).child.content.should == "##@hex_value"
end
end

Expand All @@ -215,8 +215,13 @@

describe 'Embed' do
before do
@embed = Prismic::Fragments::Embed.new('MY_TYPE', 'MY_PROVIDER', 'my_url', 'my_width',
'my_height', 'my_html', 'my_oembed_json')
@embed = Prismic::Fragments::Embed.new(
'MY_TYPE',
'MY_PROVIDER',
'my_url',
'my_html',
'my_oembed_json'
)
end

describe 'as_html' do
Expand Down
38 changes: 35 additions & 3 deletions spec/json_parsers_spec.rb
Expand Up @@ -23,7 +23,7 @@
document_link.link_type.should == "product"
document_link.tags.should == ['Macaron']
document_link.slug.should == "dark-chocolate-macaron"
document_link.is_broken.should == false
document_link.broken?.should == false
end
end

Expand Down Expand Up @@ -66,11 +66,18 @@
describe 'date_parser' do
before do
raw_json = <<json
{
"type": "date",
"value": "2013-09-19"
}
json
@json = JSON.parse(raw_json)
end

it "correctly parses Date objects"
it "correctly parses Date objects" do
date = Prismic::JsonParser.date_parser(@json)
date.value.should == Time.new(2013, 9, 19)
end
end

describe 'number_parser' do
Expand All @@ -92,12 +99,37 @@

describe 'embed_parser' do
before do
@embed_type = "rich"
@provider = "GitHub"
@url = "https://gist.github.com"
@html = '<script src="https://gist.github.com/dohzya/6762845.js"></script>'
raw_json = <<json
{
"type": "embed",
"value": {
"oembed": {
"version": "1.0",
"type": #{@embed_type.to_json},
"provider_name": #{@provider.to_json},
"provider_url": #{@url.to_json},
"html": #{@html.to_json},
"gist": "dohzya/6762845",
"embed_url": "https://gist.github.com/dohzya/6762845",
"title": "dohzya/gist:6762845"
}
}
}
json
@json = JSON.parse(raw_json)
end

it "correctly parses Embed objects"
it "correctly parses Embed objects" do
embed = Prismic::JsonParser.embed_parser(@json)
embed.embed_type.should == @embed_type
embed.provider.should == @provider
embed.url.should == @url
embed.html.should == @html
end
end

describe 'image_parser' do
Expand Down
50 changes: 27 additions & 23 deletions spec/prismic_spec.rb
Expand Up @@ -3,22 +3,24 @@
describe 'Api' do
before do
json_representation = '{"foo": "bar"}'
@master = Prismic::Ref.new('ref3', 'label3', true)
@api = Prismic::API.new(json_representation) { |api|
api.refs = {
@api = Prismic::API.new({
json: json_representation,
bookmarks: {},
tags: {},
types: {},
refs: {
'key1' => Prismic::Ref.new('ref1', 'label1'),
'key2' => Prismic::Ref.new('ref2', 'label2'),
'key3' => @master,
'key3' => Prismic::Ref.new('ref3', 'label3', true),
'key4' => Prismic::Ref.new('ref4', 'label4'),
}
api.forms = {
'form1' => Prismic::SearchForm.new(api, Prismic::Form.new('form1', {}, nil, nil, nil, nil)),
'form2' => Prismic::SearchForm.new(api, Prismic::Form.new('form2', {}, nil, nil, nil, nil)),
'form3' => Prismic::SearchForm.new(api, Prismic::Form.new('form3', {}, nil, nil, nil, nil)),
'form4' => Prismic::SearchForm.new(api, Prismic::Form.new('form4', {}, nil, nil, nil, nil)),
}
api.master = @master
}
},
forms: {
'form1' => Prismic::SearchForm.new(Prismic::Form.new('form1', {}, nil, nil, nil, nil)),
'form2' => Prismic::SearchForm.new(Prismic::Form.new('form2', {}, nil, nil, nil, nil)),
'form3' => Prismic::SearchForm.new(Prismic::Form.new('form3', {}, nil, nil, nil, nil)),
'form4' => Prismic::SearchForm.new(Prismic::Form.new('form4', {}, nil, nil, nil, nil)),
},
})
end

describe 'ref' do
Expand Down Expand Up @@ -60,7 +62,7 @@
describe 'parse_api_response' do
before do
@data = File.read("#{File.dirname(__FILE__)}/responses_mocks/api.json")
@json = Yajl::Parser.new.parse(@data)
@json = JSON.parse(@data)
@parsed = Prismic::API.parse_api_response(@json)
end

Expand Down Expand Up @@ -174,11 +176,13 @@
describe 'Document' do
before do
fragments = {
'field1' => Prismic::Fragments::StructuredText::Span.new(0, 42),
'field2' => Prismic::Fragments::DocumentLink.new(nil, nil, nil, nil, nil),
'field3' => Prismic::Fragments::WebLink.new('weburl')
'field1' => Prismic::Fragments::DocumentLink.new(nil, nil, nil, nil, nil),
'field2' => Prismic::Fragments::WebLink.new('weburl')
}
@document = Prismic::Document.new(nil, nil, nil, nil, ['my-slug'], fragments)
@link_resolver = Prismic::LinkResolver.new('master'){|doc_link|
"http://host/#{doc_link.id}"
}
end

describe 'slug' do
Expand All @@ -194,15 +198,15 @@

describe 'as_html' do
it "returns a <section> HTML element" do
Nokogiri::XML(@document.as_html(nil)).child.name.should == 'section'
Nokogiri::XML(@document.as_html(@link_resolver)).child.name.should == 'section'
end

it "returns a HTML element with a 'data-field' attribute" do
Nokogiri::XML(@document.as_html(nil)).child.has_attribute?('data-field').should be_true
Nokogiri::XML(@document.as_html(@link_resolver)).child.has_attribute?('data-field').should be_true
end

it "returns a HTML element with a 'data-field' attribute containing the name of the field" do
Nokogiri::XML(@document.as_html(nil)).child.attribute('data-field').value.should == 'field1'
Nokogiri::XML(@document.as_html(@link_resolver)).child.attribute('data-field').value.should == 'field1'
end
end
end
Expand All @@ -214,19 +218,19 @@

describe 'query' do
it "adds the query to the form's data" do
@form = Prismic::SearchForm.new(nil, Prismic::Form.new('form1', {}, nil, nil, nil, nil), {})
@form = Prismic::SearchForm.new(Prismic::Form.new('form1', {}, nil, nil, nil, nil), {})
@form.query('[bar]')
@form.data.should == { 'q' => '[bar]' }
end

it "adds existant non-nil queries (in fields) to the form's data" do
@form = Prismic::SearchForm.new(nil, Prismic::Form.new('form1', {'q' => @field}, nil, nil, nil, nil), {})
@form = Prismic::SearchForm.new(Prismic::Form.new('form1', {'q' => @field}, nil, nil, nil, nil), {})
@form.query('[bar]')
@form.data.should == { 'q' => '[foobar]' }
end

it "returns the form itself" do
@form = Prismic::SearchForm.new(nil, Prismic::Form.new('form1', {'q' => @field}, nil, nil, nil, nil), {})
@form = Prismic::SearchForm.new(Prismic::Form.new('form1', {'q' => @field}, nil, nil, nil, nil), {})
@form.query('[foo]').should == @form
end
end
Expand Down

0 comments on commit 7a05632

Please sign in to comment.