-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow setting label_ids
on a message
#231
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2bd17ce
Allow setting `label_ids` on a message
arunagw d736143
Fix rubocop
arunagw 950a7ab
Move into private method
arunagw e40e7ce
Add FilterAttributes class
arunagw 145c1d1
Better error message
arunagw a320a89
Add spec for FilterAttributes
arunagw ca7a37e
Fix cop
arunagw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module Nylas | ||
# Methods to check and raise error if extra attributes are present | ||
class FilterAttributes | ||
def initialize(attributes:, allowed_attributes:) | ||
@attributes = attributes | ||
@allowed_attributes = allowed_attributes | ||
end | ||
|
||
def check | ||
return if extra_attributes.empty? | ||
|
||
raise ArgumentError, "Only #{allowed_attributes} are allowed to be sent" | ||
end | ||
|
||
private | ||
|
||
attr_reader :attributes, :allowed_attributes | ||
|
||
def extra_attributes | ||
attributes - allowed_attributes | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Nylas::FilterAttributes do | ||
describe "#check" do | ||
context "when `attributes` and `allowed_attributes` are similar" do | ||
it "does not raise any error" do | ||
attributes = %i[foo bar] | ||
allowed_attributes = %i[foo bar] | ||
filter = described_class.new(attributes: attributes, allowed_attributes: allowed_attributes) | ||
|
||
expect { filter.check }.not_to raise_error | ||
end | ||
end | ||
|
||
context "when `attributes` and `allowed_attributes` are different" do | ||
it "raises an error" do | ||
attributes = %i[foo bar] | ||
allowed_attributes = %i[foo] | ||
filter = described_class.new(attributes: attributes, allowed_attributes: allowed_attributes) | ||
|
||
expect { filter.check }.to raise_error(ArgumentError, "Only [:foo] are allowed to be sent") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to add
starred
andunread
attributes here also? I'm not familiar with the DSL so I'm just looking at the pattern.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to check with these attributes and see what's happening. If we don't need it I will remove them from here. Thanks for the point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do have
started
andunread
define above the file so we are good. Thelabel_ids
was the missing one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are actually here https://github.com/nylas/nylas-ruby/pull/231/files#diff-6027b1238ffa1b9852b7b40018edcbabL31-L32