spec/metadata_spec.rb in rdf-tabular-0.1.1 vs spec/metadata_spec.rb in rdf-tabular-0.1.2

- old
+ new

@@ -84,24 +84,26 @@ if allowed it "validates" do params[:valid].each do |v| subject.send("#{prop}=".to_sym, v) expect(subject.errors).to be_empty + expect(subject.warnings).to be_empty end end it "invalidates" do params[:invalid].each do |v| subject.send("#{prop}=".to_sym, v) - subject.valid? - expect(subject.errors).not_to be_empty + expect(subject.errors).to be_empty + expect(subject.warnings).not_to be_empty end end else it "does not allow" do params[:valid].each do |v| subject.send("#{prop}=".to_sym, v) - expect(subject.errors).not_to be_empty + expect(subject.errors).to be_empty + expect(subject.warnings).not_to be_empty end end end end end @@ -142,11 +144,12 @@ context "invalid JSON-LD" do it "Does not allow unknown prefxies or unprefixed names" do invalid.each do |v| subject[v.to_sym] = "foo" - expect(subject.errors).not_to be_empty + expect(subject.errors).to be_empty + expect(subject.warnings).not_to be_empty end end { "value with type and language" => %({"@value": "foo", "@type": "xsd:token", "@language": "en"}), @@ -165,11 +168,12 @@ end else it "Does not allow defined prefixed names and absolute URIs" do (valid + invalid).each do |v| subject[v.to_sym] = "foo" - expect(subject.errors).not_to be_empty + expect(subject.errors).to be_empty + expect(subject.warnings).not_to be_empty end end end end @@ -195,25 +199,25 @@ end its(:type) {is_expected.to eql :Column} { - title: { + titles: { valid: ["foo", %w(foo bar), {"en" => "foo", "de" => "bar"}], invalid: [1, true, nil] }, required: { valid: [true, false], - invalid: [nil, "foo", 1, 0, "true", "false", "TrUe", "fAlSe", "1", "0"], + warning: [nil, "foo", 1, 0, "true", "false", "TrUe", "fAlSe", "1", "0"], }, suppressOutput: { valid: [true, false], - invalid: [nil, "foo", 1, 0, "true", "false", "TrUe", "fAlSe", "1", "0"], + warning: [nil, "foo", 1, 0, "true", "false", "TrUe", "fAlSe", "1", "0"], }, virtual: { valid: [true, false], - invalid: [nil, 1, 0, "true", "false", "TrUe", "fAlSe", "1", "0", "foo"], + warning: [nil, 1, 0, "true", "false", "TrUe", "fAlSe", "1", "0", "foo"], }, }.each do |prop, params| context prop.to_s do it "validates" do params[:valid].each do |v| @@ -224,21 +228,28 @@ it "invalidates" do params[:invalid].each do |v| subject.send("#{prop}=".to_sym, v) expect(subject).not_to be_valid end - end + end if params[:invalid] + it "warnings" do + params[:warning].each do |v| + subject.send("#{prop}=".to_sym, v) + expect(subject).to be_valid + expect(subject.warnings).not_to be_empty + end + end if params[:warning] end end - context "title" do + context "titles" do { string: ["foo", {"und" => ["foo"]}], }.each do |name, (input, output)| it name do - subject.title = input - expect(subject.title).to produce(output) + subject.titles = input + expect(subject.titles).to produce(output) end end end end @@ -305,11 +316,11 @@ end describe "foreignKeys" do subject { RDF::Tabular::TableGroup.new({ - resources: [{ + tables: [{ url: "a", tableSchema: { "@id" => "a_s", columns: [{name: "a1"}, {name: "a2"}], foreignKeys: [] @@ -348,11 +359,11 @@ "columnReference" => "b1" } } }.each do |name, fk| it name do - subject.resources.first.tableSchema.foreignKeys << fk + subject.tables.first.tableSchema.foreignKeys << fk expect(subject.normalize!.errors).to be_empty end end end @@ -401,11 +412,11 @@ "columnReference" => "b1" } }, }.each do |name, fk| it name do - subject.resources.first.tableSchema.foreignKeys << fk + subject.tables.first.tableSchema.foreignKeys << fk expect(subject.normalize!.errors).not_to be_empty end end end end @@ -440,17 +451,17 @@ end end end end - context "title" do + context "titles" do { string: ["foo", {"und" => ["foo"]}], }.each do |name, (input, output)| it name do - subject.title = input - expect(subject.title).to produce(output) + subject.titles = input + expect(subject.titles).to produce(output) end end end end @@ -483,14 +494,14 @@ "@type": "Table", "url": "https://example.org/countries.csv", "tableSchema": { "@type": "Schema", "columns": [ - {"title": {"und": ["countryCode"]}}, - {"title": {"und": ["latitude"]}}, - {"title": {"und": ["longitude"]}}, - {"title": {"und": ["name"]}} + {"titles": {"und": ["countryCode"]}}, + {"titles": {"und": ["latitude"]}}, + {"titles": {"und": ["longitude"]}}, + {"titles": {"und": ["name"]}} ] } }) }, "with skipRows" => { @@ -501,14 +512,14 @@ "@type": "Table", "url": "https://example.org/countries.csv", "tableSchema": { "@type": "Schema", "columns": [ - {"title": {"und": ["AD"]}}, - {"title": {"und": ["42.546245"]}}, - {"title": {"und": ["1.601554"]}}, - {"title": {"und": ["Andorra"]}} + {"titles": {"und": ["AD"]}}, + {"titles": {"und": ["42.546245"]}}, + {"titles": {"und": ["1.601554"]}}, + {"titles": {"und": ["Andorra"]}} ] }, "rdfs:comment": ["countryCode,latitude,longitude,name"] }) }, @@ -520,37 +531,19 @@ "@type": "Table", "url": "https://example.org/tree-ops.tsv", "tableSchema": { "@type": "Schema", "columns": [ - {"title": {"und": ["GID"]}}, - {"title": {"und": ["On Street"]}}, - {"title": {"und": ["Species"]}}, - {"title": {"und": ["Trim Cycle"]}}, - {"title": {"und": ["Inventory Date"]}} + {"titles": {"und": ["GID"]}}, + {"titles": {"und": ["On Street"]}}, + {"titles": {"und": ["Species"]}}, + {"titles": {"und": ["Trim Cycle"]}}, + {"titles": {"und": ["Inventory Date"]}} ] } }) }, - "headerColumnCount" => { - input: "https://example.org/tree-ops.csv", - dialect: {headerColumnCount: 1}, - result: %({ - "@context": "http://www.w3.org/ns/csvw", - "@type": "Table", - "url": "https://example.org/tree-ops.csv", - "tableSchema": { - "@type": "Schema", - "columns": [ - {"title": {"und": ["On Street"]}}, - {"title": {"und": ["Species"]}}, - {"title": {"und": ["Trim Cycle"]}}, - {"title": {"und": ["Inventory Date"]}} - ] - } - }) - }, }.each do |name, props| it name do dialect = if props[:dialect] described_class.new(props[:dialect], base: RDF::URI("http://example.org/base"), debug: @debug) else @@ -593,11 +586,11 @@ valid: [{skipRows: 1}], invalid: ["http://location-of-dialect", "foo"] }, suppressOutput: { valid: [true, false], - invalid: [nil, "foo", 1, 0, "true", "false", "TrUe", "fAlSe", "1", "0"], + warning: [nil, "foo", 1, 0, "true", "false", "TrUe", "fAlSe", "1", "0"], }, }.each do |prop, params| context prop.to_s do it "validates" do params[:valid].each do |v| @@ -608,18 +601,25 @@ it "invalidates" do params[:invalid].each do |v| subject.send("#{prop}=".to_sym, v) expect(subject).not_to be_valid end - end + end if params[:invalid] + it "warnings" do + params[:warning].each do |v| + subject.send("#{prop}=".to_sym, v) + expect(subject).to be_valid + expect(subject.warnings).not_to be_empty + end + end if params[:warning] end end end describe RDF::Tabular::TableGroup do let(:table) {{"url" => "http://example.org/table.csv"}} - subject {described_class.new({"resources" => [table]}, base: RDF::URI("http://example.org/base"), debug: @debug)} + subject {described_class.new({"tables" => [table]}, base: RDF::URI("http://example.org/base"), debug: @debug)} specify {is_expected.to be_valid} it_behaves_like("inherited properties") it_behaves_like("common properties") its(:type) {is_expected.to eql :TableGroup} @@ -747,11 +747,11 @@ "@type Table" => [{"@type" => "Table"}, RDF::Tabular::Table], "@type Transformation" => [{"@type" => "Transformation"}, RDF::Tabular::Transformation], "@type Schema" => [{"@type" => "Schema"}, RDF::Tabular::Schema], "@type Column" => [{"@type" => "Column"}, RDF::Tabular::Column], "@type Dialect" => [{"@type" => "Dialect"}, RDF::Tabular::Dialect], - "resources TableGroup" => [{"resources" => []}, RDF::Tabular::TableGroup], + "tables TableGroup" => [{"tables" => []}, RDF::Tabular::TableGroup], "dialect Table" => [{"dialect" => {}}, RDF::Tabular::Table], "tableSchema Table" => [{"tableSchema" => {}}, RDF::Tabular::Table], "transformations Table" => [{"transformations" => []}, RDF::Tabular::Table], "targetFormat Transformation" => [{"targetFormat" => "foo"}, RDF::Tabular::Transformation], "scriptFormat Transformation" => [{"scriptFormat" => "foo"}, RDF::Tabular::Transformation], @@ -763,13 +763,12 @@ "commentPrefix Dialect" => [{"commentPrefix" => "#"}, RDF::Tabular::Dialect], "delimiter Dialect" => [{"delimiter" => ","}, RDF::Tabular::Dialect], "doubleQuote Dialect" => [{"doubleQuote" => true}, RDF::Tabular::Dialect], "encoding Dialect" => [{"encoding" => "utf-8"}, RDF::Tabular::Dialect], "header Dialect" => [{"header" => true}, RDF::Tabular::Dialect], - "headerColumnCount Dialect" => [{"headerColumnCount" => 0}, RDF::Tabular::Dialect], "headerRowCount Dialect" => [{"headerRowCount" => 1}, RDF::Tabular::Dialect], - "lineTerminator Dialect" => [{"lineTerminator" => "\r\n"}, RDF::Tabular::Dialect], + "lineTerminators Dialect" => [{"lineTerminators" => "\r\n"}, RDF::Tabular::Dialect], "quoteChar Dialect" => [{"quoteChar" => "\""}, RDF::Tabular::Dialect], "skipBlankRows Dialect" => [{"skipBlankRows" => true}, RDF::Tabular::Dialect], "skipColumns Dialect" => [{"skipColumns" => 0}, RDF::Tabular::Dialect], "skipInitialSpace Dialect" => [{"skipInitialSpace" => "start"}, RDF::Tabular::Dialect], "skipRows Dialect" => [{"skipRows" => 1}, RDF::Tabular::Dialect], @@ -790,23 +789,23 @@ "@type": "Table", "tableSchema": { "@type": "Schema", "columns": [{ "name": "countryCode", - "title": "countryCode", + "titles": "countryCode", "propertyUrl": "https://example.org/countries.csv#countryCode" }, { "name": "latitude", - "title": "latitude", + "titles": "latitude", "propertyUrl": "https://example.org/countries.csv#latitude" }, { "name": "longitude", - "title": "longitude", + "titles": "longitude", "propertyUrl": "https://example.org/countries.csv#longitude" }, { "name": "name", - "title": "name", + "titles": "name", "propertyUrl": "https://example.org/countries.csv#name" }] } })), base: RDF::URI("http://example.org/base"), debug: @debug) } @@ -865,31 +864,31 @@ subject { described_class.new(JSON.parse(%({ "url": "https://example.org/countries.csv", "tableSchema": { "columns": [ - {"title": "addressCountry"}, - {"title": "latitude"}, - {"title": "longitude"}, - {"title": "name"} + {"titles": "addressCountry"}, + {"titles": "latitude"}, + {"titles": "longitude"}, + {"titles": "name"} ] } })), base: RDF::URI("http://example.org/base"), debug: @debug) } let(:input) {RDF::Util::File.open_file("https://example.org/countries.csv")} { - "default title" => { + "default titles" => { aboutUrl: [RDF::Node, RDF::Node, RDF::Node, RDF::Node], propertyUrl: [nil, nil, nil, nil], valueUrl: [nil, nil, nil, nil], md: {"url" => "https://example.org/countries.csv", "tableSchema" => { "columns" => [ - {"title" => "addressCountry"}, - {"title" => "latitude"}, - {"title" => "longitude"}, - {"title" => "name"} + {"titles" => "addressCountry"}, + {"titles" => "latitude"}, + {"titles" => "longitude"}, + {"titles" => "name"} ] } } }, "schema transformations" => { @@ -901,14 +900,14 @@ "tableSchema" => { "aboutUrl" => "{#_name}", "propertyUrl" => '{?_name}', "valueUrl" => '{_name}', "columns" => [ - {"title" => "addressCountry"}, - {"title" => "latitude"}, - {"title" => "longitude"}, - {"title" => "name"} + {"titles" => "addressCountry"}, + {"titles" => "latitude"}, + {"titles" => "longitude"}, + {"titles" => "name"} ] } } }, "PNames" => { @@ -920,21 +919,21 @@ "tableSchema" => { "aboutUrl" => 'http://schema.org/{_name}', "propertyUrl" => 'schema:{_name}', "valueUrl" => 'schema:{_name}', "columns" => [ - {"title" => "addressCountry"}, - {"title" => "latitude"}, - {"title" => "longitude"}, - {"title" => "name"} + {"titles" => "addressCountry"}, + {"titles" => "latitude"}, + {"titles" => "longitude"}, + {"titles" => "name"} ] } } }, }.each do |name, props| context name do - let(:md) {RDF::Tabular::Table.new(props[:md]).merge(subject).resources.first} + let(:md) {RDF::Tabular::Table.new(props[:md]).merge(subject).tables.first} let(:cells) {md.to_enum(:each_row, input).to_a.first.values} let(:aboutUrls) {props[:aboutUrl].map {|u| u.is_a?(String) ? md.url.join(u) : u}} let(:propertyUrls) {props[:propertyUrl].map {|u| u.is_a?(String) ? md.url.join(u) : u}} let(:valueUrls) {props[:valueUrl].map {|u| u.is_a?(String) ? md.url.join(u) : u}} it "aboutUrl is #{props[:aboutUrl]}" do @@ -959,45 +958,43 @@ { "skipRows" => {dialect: {skipRows: 1}}, "headerRowCount" => {dialect: {headerRowCount: 0}}, "skipRows + headerRowCount" => {dialect: {skipRows: 1, headerRowCount: 0}}, "skipColumns" => {dialect: {skipColumns: 1}}, - "headerColumnCount" => {dialect: {headerColumnCount: 0}}, - "skipColumns + headerColumnCount" => {dialect: {skipColumns: 1, headerColumnCount: 0}}, }.each do |name, props| context name do subject { raw = JSON.parse(%({ "url": "https://example.org/countries.csv", "@type": "Table", "tableSchema": { "@type": "Schema", "columns": [{ "name": "countryCode", - "title": "countryCode", + "titles": "countryCode", "propertyUrl": "https://example.org/countries.csv#countryCode" }, { "name": "latitude", - "title": "latitude", + "titles": "latitude", "propertyUrl": "https://example.org/countries.csv#latitude" }, { "name": "longitude", - "title": "longitude", + "titles": "longitude", "propertyUrl": "https://example.org/countries.csv#longitude" }, { "name": "name", - "title": "name", + "titles": "name", "propertyUrl": "https://example.org/countries.csv#name" }] } })) raw["dialect"] = props[:dialect] described_class.new(raw, base: RDF::URI("http://example.org/base"), debug: @debug) } let(:rows) {subject.to_enum(:each_row, input).to_a} let(:rowOffset) {props[:dialect].fetch(:skipRows, 0) + props[:dialect].fetch(:headerRowCount, 1)} - let(:columnOffset) {props[:dialect].fetch(:skipColumns, 0) + props[:dialect].fetch(:headerColumnCount, 0)} + let(:columnOffset) {props[:dialect].fetch(:skipColumns, 0)} it "has expected number attributes" do nums = [1, 2, 3, 4] nums = nums.first(nums.length - rowOffset) expect(rows.map(&:number)).to eql nums end @@ -1370,11 +1367,11 @@ "@type": "Table", "url": "http://example.org/table" })], R: %({ "@type": "TableGroup", - "resources": [{ + "tables": [{ "@type": "Table", "url": "http://example.org/table" }], "@context": "http://www.w3.org/ns/csvw" }) @@ -1388,11 +1385,11 @@ "@type": "Table", "url": "http://example.org/table2" })], R: %({ "@type": "TableGroup", - "resources": [{ + "tables": [{ "@type": "Table", "url": "http://example.org/table1" }, { "@type": "Table", "url": "http://example.org/table2" @@ -1405,18 +1402,18 @@ "@type": "Table", "url": "http://example.org/table1" }), B: [%({ "@type": "TableGroup", - "resources": [{ + "tables": [{ "@type": "Table", "url": "http://example.org/table2" }] })], R: %({ "@type": "TableGroup", - "resources": [{ + "tables": [{ "@type": "Table", "url": "http://example.org/table1" }, { "@type": "Table", "url": "http://example.org/table2" @@ -1425,22 +1422,22 @@ }) }, "table-group and table" => { A: %({ "@type": "TableGroup", - "resources": [{ + "tables": [{ "@type": "Table", "url": "http://example.org/table1" }] }), B: [%({ "@type": "Table", "url": "http://example.org/table2" })], R: %({ "@type": "TableGroup", - "resources": [{ + "tables": [{ "@type": "Table", "url": "http://example.org/table1" }, { "@type": "Table", "url": "http://example.org/table2" @@ -1449,11 +1446,11 @@ }) }, "table-group and two tables" => { A: %({ "@type": "TableGroup", - "resources": [{ + "tables": [{ "@type": "Table", "url": "http://example.org/table1" }] }), B: [%({ @@ -1465,11 +1462,11 @@ "url": "http://example.org/table2", "dc:label": "bar" })], R: %({ "@type": "TableGroup", - "resources": [{ + "tables": [{ "@type": "Table", "url": "http://example.org/table1" }, { "@type": "Table", "url": "http://example.org/table2", @@ -1503,33 +1500,33 @@ end describe "#merge!" do { "TableGroup with and without @id" => { - A: %({"@id": "http://example.org/foo", "resources": [], "@type": "TableGroup"}), - B: %({"resources": [], "@type": "TableGroup"}), - R: %({"@id": "http://example.org/foo", "resources": [], "@type": "TableGroup"}) + A: %({"@id": "http://example.org/foo", "tables": [], "@type": "TableGroup"}), + B: %({"tables": [], "@type": "TableGroup"}), + R: %({"@id": "http://example.org/foo", "tables": [], "@type": "TableGroup"}) }, "TableGroup with and without @type" => { - A: %({"resources": []}), - B: %({"resources": [], "@type": "TableGroup"}), - R: %({"resources": [], "@type": "TableGroup"}) + A: %({"tables": []}), + B: %({"tables": [], "@type": "TableGroup"}), + R: %({"tables": [], "@type": "TableGroup"}) }, - "TableGroup with matching resources" => { - A: %({"resources": [{"url": "http://example.org/foo", "dc:title": "foo"}]}), - B: %({"resources": [{"url": "http://example.org/foo", "dc:description": "bar"}]}), - R: %({"resources": [{ + "TableGroup with matching tables" => { + A: %({"tables": [{"url": "http://example.org/foo", "dc:title": "foo"}]}), + B: %({"tables": [{"url": "http://example.org/foo", "dc:description": "bar"}]}), + R: %({"tables": [{ "url": "http://example.org/foo", "dc:title": {"@value": "foo"}, "dc:description": {"@value": "bar"} }]}) }, - "TableGroup with differing resources" => { - A: %({"resources": [{"url": "http://example.org/foo", "dc:title": "foo"}]}), - B: %({"resources": [{"url": "http://example.org/bar", "dc:description": "bar"}]}), + "TableGroup with differing tables" => { + A: %({"tables": [{"url": "http://example.org/foo", "dc:title": "foo"}]}), + B: %({"tables": [{"url": "http://example.org/bar", "dc:description": "bar"}]}), R: %({ - "resources": [ + "tables": [ {"url": "http://example.org/foo", "dc:title": {"@value": "foo"}}, {"url": "http://example.org/bar", "dc:description": {"@value": "bar"}} ]}) }, "Table with tableDirection always takes A" => { @@ -1640,37 +1637,37 @@ A: %({ "@context": {"@language": "en"}, "@type": "Table", "url": "http://example.com/foo", "tableSchema": { - "columns": [{"title": "foo"}] + "columns": [{"titles": "foo"}] } }), B: %({ "@type": "Table", "url": "http://example.com/foo", "tableSchema": { - "columns": [{"title": "foo"}] + "columns": [{"titles": "foo"}] } }), R: %({ "@context": "http://www.w3.org/ns/csvw", "@type": "Table", "url": "http://example.com/foo", "tableSchema": { - "columns": [{"title": {"en": ["foo"]}}] + "columns": [{"titles": {"en": ["foo"]}}] } }), }, "Schema with matching columns merges A and B" => { A: %({"@type": "Schema", "columns": [{"name": "foo", "required": true}]}), B: %({"@type": "Schema", "columns": [{"name": "foo", "required": false}]}), R: %({"@type": "Schema", "columns": [{"name": "foo", "required": true}]}), }, "Schema with matching column titles" => { - A: %({"@type": "Schema", "columns": [{"title": "Foo"}]}), - B: %({"@type": "Schema", "columns": [{"name": "foo", "title": "Foo"}]}), - R: %({"@type": "Schema", "columns": [{"name": "foo", "title": {"und": ["Foo"]}}]}), + A: %({"@type": "Schema", "columns": [{"titles": "Foo"}]}), + B: %({"@type": "Schema", "columns": [{"name": "foo", "titles": "Foo"}]}), + R: %({"@type": "Schema", "columns": [{"name": "foo", "titles": {"und": ["Foo"]}}]}), }, "Schema with primaryKey always takes A" => { A: %({"@type": "Schema", "primaryKey": "foo"}), B: %({"@type": "Schema", "primaryKey": "bar"}), R: %({"@type": "Schema", "primaryKey": "foo"}),