Project configuration page with credentials of gems#51
Project configuration page with credentials of gems#51Shuotong wants to merge 23 commits intoAgileVentures:developfrom
Conversation
|
@Shuotong there are two failed tests, can you investigate on them? the 2nd one is failing on my branch too but the first one should be passing with your changes I think |
|
@DrakeW My features depends on a class method named credentials for every metric gem. The test passed successfully when I change the gemfile to get the gem from my forked and modified version. I already made pull requests for those gems. Once the pr goes through, the test will pass. |
|
@Shuotong I see the other PR - see my comment there, if we're adding functionality to the gem it should be test driven: AgileVentures/project_metric_slack#16 also in order to make this pass, we could monkey patch the gem in this PR to check that things actually pass in CI, e.g. class ProjectMetricSlack
def self.credentials
['token','channel']
endand then remove that in a subsequent PR - a little risky perhaps (although one can open a ticket as reminder) |
|
@Shuotong could we have a little more description in the PR above, e.g. link to relevant pivotal tracker story etc? many thanks |
app/views/projects/_form.html.haml
Outdated
| %fieldset{:id => name} | ||
| %legend= name.titleize | ||
| = hidden_field_tag "project[configs_attributes][#{index}][metric_name]", name | ||
| - existed = [] |
There was a problem hiding this comment.
this seems to be getting alot of logic in the view.
There was a problem hiding this comment.
I agree - the correct elements for display should be calculated in the controller, or even in the model or a separate service - not in the view
There was a problem hiding this comment.
The reason I am doing it in the view is that both edit and index render this form. Should I separate them and create a new view for edit?
There was a problem hiding this comment.
edit and index? you mean edit and new right? even if they are you can still pull all this into instance variables that you set in the appropriate controller actions and then minimize the code logic in the view itself
There was a problem hiding this comment.
yea. Edit and new. Sorry about that. I will move the logic to controller and make a new pull request.
app/views/projects/_form.html.haml
Outdated
| = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf' | ||
| \ : | ||
| = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf' | ||
| - classes = {'github' => ProjectMetricGithub, 'code_climate' => ProjectMetricCodeClimate, 'slack' => ProjectMetricSlack,'pivotal_tracker' => ProjectMetricPivotalTracker,'slack_trends' => ProjectMetricSlackTrends} |
There was a problem hiding this comment.
this shouldn't be hard coded here - the set of metric gems is defined in https://github.com/AgileVentures/projectscope/blob/develop/config/initializers/project_metrics.rb
there's a method to return metric names, ideally you should call this in the controller and set its value to an instance variable and then refer to that in the view:
https://github.com/AgileVentures/ProjectMetrics/blob/master/lib/project_metrics.rb#L13
There was a problem hiding this comment.
Thanks. I will then change the controller to let edit and new to render its own view rather than sharing _form.
There was a problem hiding this comment.
I don't think you need separate views, I think you need to move the logic into the controller and set instance variables appropriately and then have this form adapt based on those instance variables, but I am wrong occasionally :-)
There was a problem hiding this comment.
That makes sense. Thanks. I will think through this problem again and make a new pull request after everything works well.
app/views/projects/_form.html.haml
Outdated
| %br | ||
| - unless @readonly | ||
| - classes[name].credentials.each do |cred| | ||
| -if !existed.include?(cred) |
| name = config.metric_name | ||
| if @project_metrics[name].respond_to?(:credentials) | ||
| config.options.each_pair do |key,val| | ||
| @existed_configs[name] << key.intern |
There was a problem hiding this comment.
I think key.to_sym is more straightforward than key.intern, but they do the same thing anyways
There was a problem hiding this comment.
Good point. I will change to key.to_sym.
|
we've also got a failing test: |
|
@tansaku It actually passed test locally. Let me look into it. I think it's probably because at the time of testing, the pull requests for gems were not merged so that we didn't have credential method. Everything should be fine now. Could you please run tests again? |
|
@Shuotong re-running - we also have some merge conflicts - perhaps you can fix those - or give me permission to push to your repo to fix them for you |
|
@Shuotong still failing - try fixing the merge conflicts and running |
|
@Shuotong @DrakeW I merged, but still failing with the same error :-( |
|
@tansaku updated Gemfile.lock fixed the test |
|
|
||
| # GET /projects/1/edit | ||
| def edit | ||
| setup_metric_configs(@project) |
There was a problem hiding this comment.
I notice if I remove this all the tests still pass, and everything still works - surplus to requirement perhaps
There was a problem hiding this comment.
Yea. I've done some tests as well. And I think this line is redundant. This function is already called when rendering _form.html. And also we no longer need to include ProjectsHelper then.
| # GET /projects/1/edit | ||
| def edit | ||
| setup_metric_configs(@project) | ||
| @project.configs.each do |config| |
There was a problem hiding this comment.
actually I can remove all this code as well and everything still works ...
There was a problem hiding this comment.
The loop here checks whether certain credentials has already been given value. In _form.html, it first displays all the existed credentials and adds fields for credentials that haven't been configured. The cucumber test would pass, and everything still works if we remove this part. But on the edit page, for example, if we already have an url for codeclimate, it still provides an empty field to config url. I hope that makes sense. I should probably modify the cucumber for edit page to test this scenario.
app/views/projects/_form.html.haml
Outdated
| \ : | ||
| = text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf' | ||
| %br | ||
| - if @project_metrics[name].respond_to?(:credentials) |
There was a problem hiding this comment.
it looks like you were moving this logic into the controller, but then it wasn't removed from here
There was a problem hiding this comment.
I see. I will pass a hash mapping from the project metrics name to whether it responds to credentials method.
| @project_metrics[name] = ProjectMetrics.class_for name | ||
| end | ||
| end | ||
|
|
There was a problem hiding this comment.
slightly more rubyish version:
def set_project_metrics
@project_metrics = ProjectMetrics.metric_names.inject({}) do |hash, name|
hash[name] = ProjectMetrics.class_for name; hash
end
endsee http://stackoverflow.com/a/9434319/316729 for more alternatives
There was a problem hiding this comment.
Good point. Thanks for your suggestion. I've modified my code accordingly.
|
@DrakeW reasonable point - although can you not show the feature on the cs169 server? |
|
@tansaku we can show this on our staging server, and that would not require this to be merged right now if that's what you were saying? |
|
@DrakeW sorry I think I was mistaken - I thought you guys were deploying code to http://projectscope-cs169.herokuapp.com/projects, but after speaking to An Ju I guess you are not. Don't you have some of your own heroku instances you can deploy to? I mean I understand you wanting to merge it in and all, and it's great functionality, but with bits of code that have no function? :-) Armando is your customer - you think he wants to see the features more than he wants to see the code doing meaningful things? :-) Is there some sense in which you need it merged and deployed (to cs169, or the develop server I just created) in order to demo it to the client? Apologies if I'm not following - I'll check in on this again tomorrow |
|
the understanding is that the team can deploy to their own 'staging' server, and once i sign off on feature impelmentations, the latest features can be deployed to the cs169 production server |
|
thanks @armandofox - so then there's no rush to merge this ...? |
|
|
||
| <a href="https://codeclimate.com/github/DrakeW/projectscope"><img src="https://codeclimate.com/github/DrakeW/projectscope/badges/gpa.svg" /></a> | ||
| <a href="https://travis-ci.org/DrakeW/projectscope"><img src="https://travis-ci.org/DrakeW/projectscope.svg?branch=develop"></a> | ||
| <a href="https://codeclimate.com/github/DrakeW/projectscope/coverage"><img src="https://codeclimate.com/github/DrakeW/projectscope/badges/coverage.svg" /></a> |
There was a problem hiding this comment.
this file shouldn't be changed?
There was a problem hiding this comment.
not sure - which file are you referring to? sorry ... you mean the README? a codeclimate file?
There was a problem hiding this comment.
I mean the README, this line is our repo's code climate coverage badge
There was a problem hiding this comment.
ah, being changes from build to coverage - we should display both right?
There was a problem hiding this comment.
did I change this? sorry - I thought I was updating to be correct - feel free to set to what you think it should be - for this whole branch though the main thing we need is the refactoring of the view to use the new controller code right?
|
@Shuotong looking forward to updates on this |
|
Thanks @Shuotong - big step forward. I've made a few cosmetic changes to standardize indentation and spacing after commas, as well as renaming I guess it's time to pull this in now, but I am worried that the logic in the view and controller is still more convoluted than it needs to be. For example you use this method: def set_project_metrics
@project_metrics = ProjectMetrics.metric_names.inject({}) do |hash, name|
hash[name] = ProjectMetrics.class_for name; hash
end
endto set up a hash for use in the view like so: - name, index = cf.object.metric_name, cf.index
- @project_metrics[name].credentials.each do |cred|I think it would be a lot less effort to adjust the config model to allow it to report its class directly, e.g. class Config < ActiveRecord::Base
def klass
ProjectMetrics.class_for name
end
endand then you could have the following in the view, and no additional code in the controller: - name, klass, index = cf.object.metric_name, cf.object.klass, cf.index
- klass.credentials.each do |cred|what do you think? |
|
@DrakeW any thoughts on the above? I'd love to at least get a refactoring ticket out of this - I think moving code into models is something that @armandofox would love you all to grasp |
|
@tansaku That makes sense. I think it will be helpful for another feature I am working on, which let same services share one config so that for example, we don't need to config slack and slack_trends twice. |
|
ah yes, looks like that is the issue: AgileVentures/project_metric_code_climate#12 |
| attr_accessible :options, :metric_name | ||
|
|
||
| def klass | ||
| ProjectMetrics.class_for self.metric_name |
There was a problem hiding this comment.
2 space indenting please - let's be consistent :-)
|
@Shuotong great work - can you see any other logic you can pull into the model? Feel free to create refactoring tickets :-) I think we're closing to getting this merged ... |

User story is here. https://www.pivotaltracker.com/story/show/132780273