Skip to content

Commit

Permalink
use decribed_class in model specs so that when we change names, there…
Browse files Browse the repository at this point in the history
…'s less to do
  • Loading branch information
Floppy committed Apr 28, 2021
1 parent 8123349 commit ae646b1
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 80 deletions.
12 changes: 6 additions & 6 deletions spec/models/package_processor_spec.rb
Expand Up @@ -12,7 +12,7 @@

it "creates a package from a url" do
mock_file("http://example.com/test.csv", 'csvs/valid.csv')
processor = PackageProcessor.new({
processor = described_class.new({
urls: ['http://example.com/test.csv']
}, @package.id)
processor.process
Expand All @@ -21,7 +21,7 @@
end

it "creates a package from a data url" do
processor = PackageProcessor.new({
processor = described_class.new({
files_data: create_data_uri('csvs/valid.csv')
}, @package.id)
processor.process
Expand All @@ -30,7 +30,7 @@
end

it "creates a package from an uploaded file" do
processor = PackageProcessor.new({
processor = described_class.new({
file_ids: [
mock_upload('valid.csv')
]
Expand All @@ -41,7 +41,7 @@
end

it "creates a package from a vanilla file upload" do
processor = PackageProcessor.new({
processor = described_class.new({
files: [
mock_uploaded_file('csvs/valid.csv')
]
Expand All @@ -53,7 +53,7 @@

it "creates a package from a zipped url" do
mock_file("http://example.com/valid.zip", 'csvs/valid.zip')
processor = PackageProcessor.new({
processor = described_class.new({
urls: ['http://example.com/valid.zip']
}, @package.id)
processor.process
Expand All @@ -66,7 +66,7 @@
StoredChunk.save('chunked_file', i.to_s, i)
end

processor = PackageProcessor.new({
processor = described_class.new({
file_ids: [
'chunked_file,10'
]
Expand Down
34 changes: 17 additions & 17 deletions spec/models/package_spec.rb
Expand Up @@ -12,7 +12,7 @@

it "creates a single validation" do
mock_file("http://example.org/valid.csv", 'csvs/valid.csv')
package = Package.new
package = described_class.new
package = package.create_package(['http://example.org/valid.csv'])
expect(package.validations.length).to eq(1)
end
Expand All @@ -33,13 +33,13 @@
end

it "creates multiple validations" do
package = Package.new
package = described_class.new
package = package.create_package(@urls)
expect(package.validations.length).to eq(4)
end

it "sets the right type" do
package = Package.new
package = described_class.new
package = package.create_package(@urls)
expect(package.type).to eq("urls")
end
Expand All @@ -49,7 +49,7 @@
mock_file(schema_url, 'schemas/valid.json', 'application/javascript')

schema = Csvlint::Schema.load_from_uri(schema_url)
package = Package.new
package = described_class.new
package = package.create_package(@urls, schema_url, schema)

package.validations.each do |validation|
Expand All @@ -72,13 +72,13 @@
end

it "creates multiple validations" do
package = Package.new
package = described_class.new
package = package.create_package(@files)
expect(package.validations.length).to eq(4)
end

it "sets the right type" do
package = Package.new
package = described_class.new
package = package.create_package(@files)
expect(package.type).to eq("files")
end
Expand All @@ -88,7 +88,7 @@
mock_file(schema_url, 'schemas/valid.json', 'application/javascript')

schema = Csvlint::Schema.load_from_uri(schema_url)
package = Package.new
package = described_class.new
package = package.create_package(@files, schema_url, schema)

package.validations.each do |validation|
Expand All @@ -107,7 +107,7 @@
mock_file(url, 'datapackages/single-datapackage.json', 'application/javascript')
mock_file("http://example.org/valid.csv", 'csvs/valid.csv')

package = Package.new
package = described_class.new
package = package.create_package([url])
dataset = DataKitten::Dataset.new(access_url: url)
package_dataset = Marshal.load(package.dataset)
Expand All @@ -127,7 +127,7 @@
mock_file("http://example.org/valid.csv", 'csvs/valid.csv')
mock_file("http://example.org/valid2.csv", 'csvs/valid.csv')

package = Package.new
package = described_class.new
package = package.create_package([url])

expect(package.validations.length).to eq(2)
Expand All @@ -138,7 +138,7 @@
mock_file(url, 'datapackages/datapackage-with-schema.json', 'application/javascript')
mock_file("http://example.org/all_constraints.csv", 'csvs/all_constraints.csv')

package = Package.new
package = described_class.new
package = package.create_package([url])
result = Marshal.load package.validations.first.result

Expand All @@ -160,7 +160,7 @@
mock_file(url, 'datapackages/non-csv-datapackage.json', 'application/javascript')
mock_file("http://example.org/some-json.json", 'datapackages/non-csv-datapackage.json')

package = Package.new
package = described_class.new
package = package.create_package([url])

expect(package).to eq(nil)
Expand All @@ -172,7 +172,7 @@
mock_file("http://example.org/some-json.json", 'csvs/valid.csv')
mock_file("http://example.org/valid.csv", 'csvs/valid.csv')

package = Package.new
package = described_class.new
package = package.create_package([url])

expect(package.validations.length).to eq(1)
Expand All @@ -186,7 +186,7 @@
files = [ mock_uploaded_file('datapackages/single-datapackage.json') ]
mock_file("http://example.org/valid.csv", 'csvs/valid.csv')

package = Package.new
package = described_class.new
package = package.create_package(files)
expect(package.validations.length).to eq(1)

Expand All @@ -196,7 +196,7 @@
files = [ mock_uploaded_file('datapackages/local-and-remote-datapackage.json') ]
mock_file("http://example.org/valid.csv", 'csvs/valid.csv')

package = Package.new
package = described_class.new
package = package.create_package(files)
expect(package.validations.length).to eq(1)

Expand All @@ -216,7 +216,7 @@
it "creates a validation for a CKAN package with a single CSV", :vcr do
url = 'http://data.gov.uk/dataset/uk-open-access-non-vosa-sites'

package = Package.new
package = described_class.new
package = package.create_package([url])
dataset = DataKitten::Dataset.new(access_url: url)
package_dataset = Marshal.load(package.dataset)
Expand All @@ -233,7 +233,7 @@
it "creates multiple validations for a datapackage with multiple CSVs", :vcr do
url = 'http://data.gov.uk/dataset/uk-civil-service-high-earners'

package = Package.new
package = described_class.new
package = package.create_package([url])

expect(package.validations.length).to eq(4)
Expand All @@ -242,7 +242,7 @@
it "returns nil if there are no CSVs", :vcr do
url = 'http://data.gov.uk/dataset/ratio-of-median-house-price-to-median-earnings'

package = Package.new
package = described_class.new
package = package.create_package([url])
expect(package).to eq(nil)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/models/schema_processor_spec.rb
Expand Up @@ -11,7 +11,7 @@
schema_url = "http://example.org/schema.json"
mock_file(schema_url, @schema, 'application/javascript')

schema = SchemaProcessor.new(url: schema_url).schema
schema = described_class.new(url: schema_url).schema

expect(schema.fields.count).to eq(3)
expect(schema.fields[0].name).to eq("FirstName")
Expand All @@ -21,7 +21,7 @@

it "reads a schema from a data URI" do
schema_data = create_data_uri(@schema, 'application/json')
schema = SchemaProcessor.new(data: schema_data).schema
schema = described_class.new(data: schema_data).schema

expect(schema.fields.count).to eq(3)
expect(schema.fields[0].name).to eq("FirstName")
Expand All @@ -31,7 +31,7 @@

it "reads a schema from a file" do
file = mock_uploaded_file(@schema, 'application/json')
schema = SchemaProcessor.new(file: file).schema
schema = described_class.new(file: file).schema

expect(schema.fields.count).to eq(3)
expect(schema.fields[0].name).to eq("FirstName")
Expand All @@ -42,7 +42,7 @@
context "with datapackage" do
before(:each) do
@file = mock_uploaded_file('datapackages/datapackage-with-schema.json', 'application/json')
@schema = SchemaProcessor.new(file: @file)
@schema = described_class.new(file: @file)
end

it "detects a datapackage" do
Expand Down
44 changes: 22 additions & 22 deletions spec/models/summary_spec.rb
@@ -1,70 +1,70 @@
require "spec_helper"

describe Summary, type: :model do

context "when generating summary" do
before(:each) do
mock_file("http://example.com/test.csv", 'csvs/valid.csv')
validation = Validation.create_validation("http://example.com/test.csv")

mock_file("http://example.com/test2.csv", 'csvs/errors.csv')
validation = Validation.create_validation("http://example.com/test2.csv")

mock_file("http://www.example.com/test3.csv", 'csvs/warnings.csv')
validation = Validation.create_validation("http://www.example.com/test3.csv")
@summary = Summary.generate

@summary = described_class.generate
end

it "should record number of valid sources" do
expect(@summary.states["valid"]).to eq(1)
end

it "should record number of invalid sources" do
expect(@summary.states["invalid"]).to eq(1)
end

it "should record number of not found sources" do
expect(@summary.states["not_found"]).to eq(0)
end
end

it "should record number of sources with warnings" do
expect(@summary.states["warnings"]).to eq(1)
end
end

it "should record number of unique sources" do
expect(@summary.sources).to eq(3)
end

it "should record number of sources per host" do
expect(@summary.hosts.keys.length).to eq(1)
expect(@summary.hosts["example\uff0ecom"]).to eq(3)
end
end

it "should record occurences of errors" do
expect(@summary.level_summary.errors_breakdown[:ragged_rows]).to eq(1)
expect(@summary.level_summary.warnings_breakdown[:check_options]).to eq(1)
end

it "should count occurences across population of sources" do
mock_file("http://example.com/test4.csv", 'csvs/multiple_errors.csv')
validation = Validation.create_validation("http://example.com/test4.csv")
@summary = Summary.generate
validation = Validation.create_validation("http://example.com/test4.csv")
@summary = described_class.generate
expect(@summary.sources).to eq(4)
expect(@summary.states["invalid"]).to eq(2)
expect(@summary.level_summary.errors_breakdown[:ragged_rows]).to eq(2)
expect(@summary.level_summary.warnings_breakdown[:check_options]).to eq(1)
end

it "should record categories of problem" do
mock_file("http://example.com/test4.csv", 'csvs/multiple_errors.csv')
validation = Validation.create_validation("http://example.com/test4.csv")
@summary = Summary.generate
expect(@summary.sources).to eq(4)
@summary = described_class.generate
expect(@summary.sources).to eq(4)
expect(@summary.level_summary.errors_breakdown[:ragged_rows]).to eq(2)
expect(@summary.category_summary.structure_breakdown[:ragged_rows]).to eq(2)
end

end
end

end

0 comments on commit ae646b1

Please sign in to comment.