-
Notifications
You must be signed in to change notification settings - Fork 569
Autocomplete for starter code repo #508
Autocomplete for starter code repo #508
Conversation
- Add a new controller `AutocompleteController`. - Add a new route to `routes.rb`. - Add a new attribute `github_search_client` to `user.rb`. - Add a new view file for autocomplete suggestions.
@@ -12,6 +12,9 @@ | |||
match '/auth/:provider/callback', to: 'sessions#create', via: [:get, :post] | |||
match '/auth/failure', to: 'sessions#failure', via: [:get, :post] | |||
|
|||
# autocomplete |
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.
This comment isn't really needed, would you mind taking it out?
@cyhsutw would you mind using this spinner instead? |
# TODO: test with IE 8 | ||
# onpropertychange -> oninput for IE 8 | ||
# https://msdn.microsoft.com/en-us/library/ms536956(v=vs.85).aspx | ||
$('#autocomplete-textfield').on('focus input propertychange', -> |
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.
GitHub doesn't support IE 8 https://help.github.com/articles/supported-browsers/, so we don't have to worry about testing for that.
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'm also not a huge fan of id
based javascript bindings.
Generally what I do is add another class to the DOM object and add a js-
prefix to it.
Example.
<dd><input class="textfield js-autocomplete-textfield" ...>...</dd>
So then your coffee would look like
$('.js-autocomplete-textfield').on('focus input propertychange', ->
@cyhsutw this is looking really good so far, I left some comments. Regarding the testing we don't really do any markup testing right now. What I would do is make controller tests that verify that you get search results from the controller action. |
- Remove redundant comments in `.scss`, `.coffee` and `.html.erb`. - Change `id`-based bindings to `class`-based ones. - Add `autocomplete="off"` to `textfield` of `group_assignment_form_options`.
…lassroom into starter-code-repo-autocomplete
Hi @tarebyte thanks for reviewing my code. Your comments are really helpful for me to improve my coding styles. I've updated my code according to your suggestions, please review them when you are available. Thank you! 😄 |
I've updated the code based on your suggestions, please review them when you are available. Thank you! 😄 |
@tarebyte does this mean that we only test if the endpoint works? I tried to write some tests for the RSpec.describe AutocompleteController, type: :controller do
let(:organization) { GitHubFactory.create_owner_classroom_org }
let(:user) { organization.users.first }
before do
sign_in(user)
end
describe 'GET #github_repos', :vcr do
it 'returns success and returns repos of the user' do
get :github_repos
expect(response).to have_http_status(:success)
expect(response).to render_template(partial: 'autocomplete/_repository_suggestions')
end
it 'returns success and returns search results of a query' do
get :github_repos, query: 'rails'
expect(response).to have_http_status(:success)
expect(response).to render_template(partial: 'autocomplete/_repository_suggestions')
end
end
end I don't know if it's a proper way to test this controller. Could you please give me some advice? Thanks! 😄 |
@cyhsutw sorry for not being more clear, I meant test that a known search gives you back the results you expect. Like |
|
||
private | ||
|
||
def required_scopes |
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.
How does this behave if we don't have the right scopes? Since we're requesting this endpoint via ajax, there's no opportunity to ask for more scopes.
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.
Currently, there isn't any error handling in this controller (which is bad), I will try to add some of them to make it more robust.
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 #required_scopes
method is used to request more scopes for the user if necessary. In this case it doens't really make sense, since it's happening in the context of an ajax request.
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.
Sorry for misunderstanding the meaning of the method. I'll pushed a fix later tonight.
Thank you for pointing this out.
- Modify AssignmentController & GroupAssignmentController to accept `repo_id` as a param. - Modify markup & coffeescript to send `repo_id` as a param. - Add specs to test `repo_id` param functionalities.
…lassroom into starter-code-repo-autocomplete
Thank you very much for taking time to review my code 😄 I've update my code based on your suggestions. Short summary:
|
@johndbritton I saw this message in this PR, I'd like to know if there's anything I can help with? |
@cyhsutw that's because the log it GitHub employee only 😄 We were trying to see if we could use our internal tools to branch deploy a fork, it doesn't look like we can though |
@tarebyte Thanks for the explanation! 😄 |
@cyhsutw can you merge master back in one more time? I think this is good to 🚢 |
@@ -66,6 +66,23 @@ | |||
expect(flash[:error]).to eql('Invalid repository name, use the format owner/name') | |||
end | |||
end | |||
|
|||
context 'repo_id for starter_code is passed' 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 need one more context here invalid repo_id for starter_code is passed
, this could be the case of a repository the user doesn't have access to or an invalid input for repo_id
like the string abc
or 0
.
@cyhsutw Left a few more inline notes, but this is looking very good. Once those last few things are addressed I think this is ready to deploy. |
@johndbritton @tarebyte Thanks for spending time reviewing my code. I've updated the code based on your suggestions.
Actually, the controller DOES create assignments with those invalid |
@cyhsutw Thank you for your contribution, this has been deployed to production. |
@johndbritton @tarebyte Thank you for taking time reviewing my code, helped me a lot! |
Hello guys,
This should fix #480.
Here's a short demo:
education/t
, it will search the the repositories under namespace education (in this case, it will showeducation/teachers_pet
andeducation/teachers
).rails
.Issues with Testing
Previously, I have the
AutocompleteController
generate JSON responses and use CoffeeScript to create suggestion elements.After digging into the code base, I found using the
render_partial
might be more extensible for future additions like searchingusers
.After this change, it becomes hard to write tests since we will deal with the HTML contents which is relatively harder to validate.
One possible solution is making the controller support both HTML and JSON and the tests will check the JSON responses instead of HTML responses.
Is there any good way to make the
AutocompleteController
more testable?I would love to participate GSoC 2016 and this is my first PR for the Classroom. I would be very grateful if you can provide any advice/feedback 😄
Thank you!