-
Notifications
You must be signed in to change notification settings - Fork 27
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
Sockets-Grace & Bita #23
base: master
Are you sure you want to change the base?
Conversation
slack.rbWhat We're Looking For
In general this is a strong submission. You do a good job of implementing the design, and it is clear to me that the learning goals around the request/response cycle and consuming an API, as well as working with inheritance, were met. I do see room for growth around identifying test cases, and around general attention to detail. Please review my inline comments below, and keep up the hard work! |
|
||
CHANNEL_URL = "https://slack.com/api/channels.list" | ||
USER_URL = "https://slack.com/api/users.list" | ||
POST_URL = "https://slack.com/api/chat.postMessage" |
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.
Ideally the superclass would not need to know these details from the subclass. One of the benefits of inheritance is it allows you to add new subclasses without changing the parent class.
To do so, instead of using a constant for this, you could define a template method list_url
which is overridden in the child classes to return the correct endpoint.
That would also allow you to get rid of the if
statement in self.get
below.
when "list users" | ||
puts workspace.show_details("users") | ||
when "list channels" | ||
puts workspace.show_details("channels") |
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.
These should be calling print_details
, not show_details
else | ||
puts workspace.show_details | ||
end | ||
when "send message" |
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.
You have the wrong number of arguments to show_details
here.
name = member["name"] | ||
real_name = member["real_name"] | ||
new_member = User.new(slack_id, name, real_name) | ||
members_list << new_member |
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.
You are missing two arguments in the call to User.new
here
selected = channels.select do |channel| | ||
channel.name == user_input || channel.slack_id == user_input | ||
end | ||
@selected = selected.first |
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.
Ruby's .find
enumerable does the same thing as .select.first
.
it "returns channel details from show_details" do | ||
VCR.use_cassette("slack_workspace") do | ||
@workspace.select_channel("random") | ||
expect(@workspace.show_details).must_be_kind_of String |
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.
What if you try to show details without having first selected something?
it "returns user details from show_details" do | ||
VCR.use_cassette("slack_workspace") do | ||
@workspace.select_user("grace.m.shea") | ||
expect(@workspace.show_details).must_be_kind_of String |
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.
What happens if you call show_details
and send_message
without first selecting a user or channel?
it "raises an error for invalid channel" do | ||
VCR.use_cassette("slack-posts") do | ||
@workspace.select_channel("everyone") | ||
@workspace.selected.slack_id = "whatever" |
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 like these edge cases!
user = response.first | ||
|
||
expect(response).wont_be_nil | ||
expect(response.first.name).must_equal user.name |
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.
The expectation on line 11 is not useful, you've essentially said expect(response.first.name).must_equal response.first.name
, which will always be true.
describe "User class" do | ||
describe "self.list" do | ||
it "can return all users" do | ||
VCR.use_cassette("slack_user") do |
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.
You should include tests for User
's entire public interface: User.list
, the constructor, User#details
, and User#send_message
.
slack.rb
Congratulations! You're submitting your assignment!
You and your partner should collaborate on the answers to these questions.
Comprehension Questions