Skip to content

Commit

Permalink
Fix standard lint errors; lock version
Browse files Browse the repository at this point in the history
We didn't have a version lock on standardrb, and since it's still
pre-1.0, a lot of the default rules are changing, which means it
introduces breakages to our tests. This locks the version to the latest
as of now and applys the fixes to get it passing
  • Loading branch information
wadetandy committed Jul 16, 2020
1 parent 573fd22 commit fe0e186
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 137 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Expand Up @@ -3,6 +3,8 @@ source "https://rubygems.org"
# Specify your gem's dependencies in graphiti.gemspec
gemspec

gem "standard", "0.4.7"

group :test do
gem "pry"
gem "pry-byebug", platform: [:mri]
Expand Down
4 changes: 2 additions & 2 deletions Guardfile
@@ -1,7 +1,7 @@
guard :rspec, cmd: "bundle exec rspec --color --format documentation" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
watch(%r{^spec/(.*)\/?(.*)_spec\.rb$})
watch(%r{^spec/(.*)/?(.*)_spec\.rb$})

# Feel free to open issues for suggestions and improvements

Expand All @@ -21,7 +21,7 @@ guard :rspec, cmd: "bundle exec rspec --color --format documentation" do
watch(rails.controllers) do |m|
[
rspec.spec.call("controllers/#{m[1]}_controller"),
rspec.spec.call("api/#{m[1]}"),
rspec.spec.call("api/#{m[1]}")
]
end

Expand Down
1 change: 0 additions & 1 deletion graphiti.gemspec
Expand Up @@ -31,5 +31,4 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "activemodel", ">= 4.1"
spec.add_development_dependency "graphiti_spec_helpers", "1.0.beta.4"
spec.add_development_dependency "standard"
end
2 changes: 1 addition & 1 deletion lib/graphiti/extensions/extra_attribute.rb
Expand Up @@ -43,7 +43,7 @@ module ClassMethods
def extra_attribute(name, options = {}, &blk)
allow_field = proc {
if options[:if]
next false unless instance_exec(&options[:if])
next false unless instance_exec(&options[:if])
end

@extra_fields &&
Expand Down
44 changes: 22 additions & 22 deletions spec/filtering_spec.rb
Expand Up @@ -75,7 +75,7 @@ def self.name
context "and an array of json objects passed" do
before do
params[:filter] = {
by_json: '{ "id": 2, "id2": 3 },{ "id": 4 },{ "id": 5 },{ "id": 6 }',
by_json: '{ "id": 2, "id2": 3 },{ "id": 4 },{ "id": 5 },{ "id": 6 }'
}
end

Expand Down Expand Up @@ -115,8 +115,8 @@ def self.name
params[:filter] = {
by_json: {
users: {update: {id: {a: 2, b: 3}}},
admins: {update: {id: {a: 2, b: 3}}},
}.to_json,
admins: {update: {id: {a: 2, b: 3}}}
}.to_json
}
end

Expand All @@ -141,8 +141,8 @@ def self.name
params[:filter] = {
by_json: [
{id: [{a: 2}, {b: 3}]}.to_json,
{id: [{a: 2}, {b: 3}]}.to_json,
].join(","),
{id: [{a: 2}, {b: 3}]}.to_json
].join(",")
}
end

Expand Down Expand Up @@ -181,7 +181,7 @@ def self.name
write: foo,
kind: "record",
canonical_name: :hash,
description: "Foo",
description: "Foo"
}
resource.filter :blah, :custom do
eq do |scope, hash|
Expand Down Expand Up @@ -221,7 +221,7 @@ def self.name
expect(records.map(&:id)).to eq([
employee1.id,
employee2.id,
employee4.id,
employee4.id
])
end
end
Expand Down Expand Up @@ -443,7 +443,7 @@ def self.name
before do
params[:filter] = {
id: employee1.id,
'positions.title': "bar",
'positions.title': "bar"
}
params[:include] = "positions"
end
Expand All @@ -470,7 +470,7 @@ def self.name
before do
params[:filter] = {
id: employee1.id,
'positions.department.name': "bar",
'positions.department.name': "bar"
}
params[:include] = "positions.department"
end
Expand Down Expand Up @@ -604,7 +604,7 @@ def self.name
params[:filter] = {first_name: {eq: "Harold"}}
expect {
records
}.to raise_error(Graphiti::Errors::InvalidFilterValue, /Allowlist: \[\"William\"\]/)
}.to raise_error(Graphiti::Errors::InvalidFilterValue, /Allowlist: \["William"\]/)
end

it "accepts values in the allowlist" do
Expand All @@ -628,7 +628,7 @@ def self.name
params[:filter] = {first_name: {eq: "Harold"}}
expect {
records
}.to raise_error(Graphiti::Errors::InvalidFilterValue, /Denylist: \[\"Harold\"\]/)
}.to raise_error(Graphiti::Errors::InvalidFilterValue, /Denylist: \["Harold"\]/)
end

it "accepts values not in the denylist" do
Expand Down Expand Up @@ -701,7 +701,7 @@ def self.name
params[:filter] = {first_name: {eq: "Harold"}}
expect {
records
}.to raise_error(Graphiti::Errors::InvalidFilterValue, /Denylist: \[\"Harold\"\]/)
}.to raise_error(Graphiti::Errors::InvalidFilterValue, /Denylist: \["Harold"\]/)
end

it "accepts values not in the denylist" do
Expand Down Expand Up @@ -762,7 +762,7 @@ def self.name
params[:filter] = {
foo: "a",
bar: "b",
baz: "c",
baz: "c"
}
end

Expand Down Expand Up @@ -1134,10 +1134,10 @@ def assert_filter_value(value)
"foo" => {
"eq" => {
"bar" => {
"baz" => "blah",
},
},
},
"baz" => "blah"
}
}
}
}
end

Expand Down Expand Up @@ -1274,7 +1274,7 @@ def assert_filter_value(value)
read: type,
write: type,
kind: "scalar",
description: "test",
description: "test"
}
resource.attribute :foo, :custom
end
Expand Down Expand Up @@ -1319,7 +1319,7 @@ def assert_filter_value(value)
:suffix,
:not_suffix,
:match,
:not_match,
:not_match
])
expect(resource.filters[:foo][:operators][:eq]).to be_a(Proc)
expect(resource.filters[:foo][:operators][:suffix]).to be_nil
Expand Down Expand Up @@ -1429,7 +1429,7 @@ def assert_filter_value(value)

it "limits available operators" do
expect(resource.filters[:foo][:operators].keys).to eq([
:gt, :gte, :lt, :lte, :foo,
:gt, :gte, :lt, :lte, :foo
])
end
end
Expand All @@ -1444,7 +1444,7 @@ def assert_filter_value(value)

it "limits available operators, adding custom ones" do
expect(resource.filters[:foo][:operators].keys).to eq([
:gt, :gte, :lt, :lte, :foo,
:gt, :gte, :lt, :lte, :foo
])
end
end
Expand All @@ -1456,7 +1456,7 @@ def assert_filter_value(value)

it "limits available operators" do
expect(resource.filters[:foo][:operators].keys).to eq([
:not_eq, :gt, :gte, :lt, :lte,
:not_eq, :gt, :gte, :lt, :lte
])
end
end
Expand Down
38 changes: 19 additions & 19 deletions spec/integration/rails/finders_spec.rb
Expand Up @@ -868,7 +868,7 @@ def resource
"birthdays" => 70, # alias
"float_age" => 70.03,
"decimal_age" => "70.033",
"active" => true,
"active" => true
})
expect(included.map(&:jsonapi_type).uniq).to match_array(%w[books])
end
Expand All @@ -889,7 +889,7 @@ def resource
it "is able to sideload without adding the field" do
do_index({
fields: {authors: "first_name"},
include: "books",
include: "books"
})
expect(json["data"][0]["relationships"]).to be_present
expect(included.map(&:jsonapi_type).uniq).to match_array(%w[books])
Expand All @@ -907,7 +907,7 @@ def resource
let(:request) do
do_index({
include: "books",
page: {books: {size: 1, number: 2}},
page: {books: {size: 1, number: 2}}
})
end

Expand Down Expand Up @@ -1095,15 +1095,15 @@ def resource
it "allows filtering of sideloaded resource" do
do_index({
include: "hobbies",
filter: {hobbies: {id: hobby2.id}},
filter: {hobbies: {id: hobby2.id}}
})
expect(included("hobbies").map(&:id)).to eq([hobby2.id])
end

it "allows extra fields for sideloaded resource" do
do_index({
include: "hobbies",
extra_fields: {hobbies: "reason"},
extra_fields: {hobbies: "reason"}
})
hobby = included("hobbies")[0]
expect(hobby["name"]).to be_present
Expand All @@ -1123,7 +1123,7 @@ def resource
do_index({
include: "hobbies",
fields: {hobbies: "name"},
extra_fields: {hobbies: "reason"},
extra_fields: {hobbies: "reason"}
})
hobby = included("hobbies")[0]
expect(hobby).to have_key("name")
Expand All @@ -1135,7 +1135,7 @@ def resource
do_index({
include: "hobbies,books",
fields: {hobbies: "name", books: "title"},
extra_fields: {hobbies: "reason", books: "alternate_title"},
extra_fields: {hobbies: "reason", books: "alternate_title"}
})
hobby = included("hobbies")[0]
book = included("books")[0]
Expand Down Expand Up @@ -1216,8 +1216,8 @@ def resource
expect(target.relationships["mentors"]).to eq({
"data" => [
{"type" => "authors", "id" => author_with_mentees.id.to_s},
{"type" => "authors", "id" => author_with_both.id.to_s},
],
{"type" => "authors", "id" => author_with_both.id.to_s}
]
})
end

Expand Down Expand Up @@ -1271,7 +1271,7 @@ def resource
expect(included("hobbies").map(&:id)).to eq([hobby1.id, hobby2.id])
end

describe 'filtering relationship' do
describe "filtering relationship" do
controller(ApplicationController) do
def index
records = Legacy::HobbyResource.all(params)
Expand All @@ -1281,11 +1281,11 @@ def index

before do
allow(controller.request.env).to receive(:[])
.with("PATH_INFO") { '/legacy/hobbies' }
.with("PATH_INFO") { "/legacy/hobbies" }
end

it "can filter the relationship by the custom name" do
do_index(filter: { the_id_of_the_author: [author1.id, author2.id].join(',') })
do_index(filter: {the_id_of_the_author: [author1.id, author2.id].join(",")})
expect(d.map(&:id)).to eq([hobby1.id, hobby2.id])
end
end
Expand Down Expand Up @@ -1346,9 +1346,9 @@ def index
filter: {
taggable_id: [
{id: author1.id, type: author1.class.name}.to_json,
{id: book2.id, type: book2.class.name}.to_json,
],
},
{id: book2.id, type: book2.class.name}.to_json
]
}
})
expect(d.map(&:name)).to eq(%w[One Two Three])
end
Expand Down Expand Up @@ -1384,7 +1384,7 @@ def index
book2.save!
do_index({
filter: {books: {id: book1.id}, other_books: {id: book2.id}},
include: "books.genre,other_books.genre",
include: "books.genre,other_books.genre"
})
expect(included("genres").length).to eq(2)
end
Expand All @@ -1394,7 +1394,7 @@ def index
it "allows extra fields for the sideloaded resource" do
do_index({
include: "dwelling",
extra_fields: {houses: "house_price", condos: "condo_price"},
extra_fields: {houses: "house_price", condos: "condo_price"}
})
house = included("houses")[0]
expect(house["name"]).to be_present
Expand All @@ -1409,7 +1409,7 @@ def index
it "allows sparse fieldsets for the sideloaded resource" do
do_index({
include: "dwelling",
fields: {houses: "name", condos: "condo_description"},
fields: {houses: "name", condos: "condo_description"}
})
house = included("houses")[0]
expect(house["name"]).to be_present
Expand All @@ -1425,7 +1425,7 @@ def index
do_index({
include: "dwelling",
fields: {houses: "name", condos: "condo_description"},
extra_fields: {houses: "house_price", condos: "condo_price"},
extra_fields: {houses: "house_price", condos: "condo_price"}
})
house = included("houses")[0]
condo = included("condos")[0]
Expand Down

0 comments on commit fe0e186

Please sign in to comment.