Skip to content

Comments

Project configuration page with credentials of gems#51

Open
Shuotong wants to merge 23 commits intoAgileVentures:developfrom
junyu-w:config
Open

Project configuration page with credentials of gems#51
Shuotong wants to merge 23 commits intoAgileVentures:developfrom
junyu-w:config

Conversation

@Shuotong
Copy link

@Shuotong Shuotong commented Oct 21, 2016

@junyu-w
Copy link
Contributor

junyu-w commented Oct 21, 2016

@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

@Shuotong
Copy link
Author

@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.

@tansaku
Copy link
Contributor

tansaku commented Oct 23, 2016

@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']
  end

and then remove that in a subsequent PR - a little risky perhaps (although one can open a ticket as reminder)

@tansaku
Copy link
Contributor

tansaku commented Oct 23, 2016

@Shuotong could we have a little more description in the PR above, e.g. link to relevant pivotal tracker story etc? many thanks

%fieldset{:id => name}
%legend= name.titleize
= hidden_field_tag "project[configs_attributes][#{index}][metric_name]", name
- existed = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems to be getting alot of logic in the view.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea. Edit and new. Sorry about that. I will move the logic to controller and make a new pull request.

= 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}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I will then change the controller to let edit and new to render its own view rather than sharing _form.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Thanks. I will think through this problem again and make a new pull request after everything works well.

%br
- unless @readonly
- classes[name].credentials.each do |cred|
-if !existed.include?(cred)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer unless to if !

name = config.metric_name
if @project_metrics[name].respond_to?(:credentials)
config.options.each_pair do |key,val|
@existed_configs[name] << key.intern
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think key.to_sym is more straightforward than key.intern, but they do the same thing anyways

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I will change to key.to_sym.

@tansaku
Copy link
Contributor

tansaku commented Oct 26, 2016

@Shuotong huge improvement - thanks! - now we need to merge this to the upstream develop after I pulled in @DrakeW 's other PR

@tansaku
Copy link
Contributor

tansaku commented Oct 26, 2016

we've also got a failing test:

    And I enter new "Code Climate" config values:                     # features/step_definitions/project_steps.rb:6
      | key     | value |
      | url     | a.com |
      | channel | 12345 |
      | token   | 555   |
      Unable to find field "code_climate_url" (Capybara::ElementNotFound)
      ./features/step_definitions/project_steps.rb:10:in `block (2 levels) in <top (required)>'
      ./features/step_definitions/project_steps.rb:8:in `each'
      ./features/step_definitions/project_steps.rb:8:in `/^I enter new "(.*)" config values/'
      features/add_project_with_config.feature:13:in `And I enter new "Code Climate" config values:'

@Shuotong
Copy link
Author

@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?

@tansaku
Copy link
Contributor

tansaku commented Oct 27, 2016

@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

@tansaku
Copy link
Contributor

tansaku commented Oct 27, 2016

@Shuotong still failing - try fixing the merge conflicts and running bundle update

@tansaku
Copy link
Contributor

tansaku commented Nov 2, 2016

@Shuotong @DrakeW I merged, but still failing with the same error :-(

    And I enter new "Code Climate" config values:                     # features/step_definitions/project_steps.rb:6
      | key     | value |
      | url     | a.com |
      | channel | 12345 |
      | token   | 555   |
      Unable to find field "code_climate_url" (Capybara::ElementNotFound)
      ./features/step_definitions/project_steps.rb:10:in `block (2 levels) in <top (required)>'
      ./features/step_definitions/project_steps.rb:8:in `each'
      ./features/step_definitions/project_steps.rb:8:in `/^I enter new "(.*)" config values/'
      features/add_project_with_config.feature:13:in `And I enter new "Code Climate" config values:'```

@junyu-w
Copy link
Contributor

junyu-w commented Nov 2, 2016

@tansaku updated Gemfile.lock fixed the test


# GET /projects/1/edit
def edit
setup_metric_configs(@project)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice if I remove this all the tests still pass, and everything still works - surplus to requirement perhaps

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I can remove all this code as well and everything still works ...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

\ :
= text_field_tag "project[configs_attributes][#{index}][new][]", '', :id => nil, :class => 'newf'
%br
- if @project_metrics[name].respond_to?(:credentials)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like you were moving this logic into the controller, but then it wasn't removed from here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
  end

see http://stackoverflow.com/a/9434319/316729 for more alternatives

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Thanks for your suggestion. I've modified my code accordingly.

@tansaku
Copy link
Contributor

tansaku commented Nov 3, 2016

@DrakeW @Shuotong well done getting this working - I reviewed in detail and found some code that wasn't doing what it was supposed to - I think there's a little more logic to clean out of the view - I guess we could be making refactoring tickets if there was a rush to merge this in ...

@junyu-w
Copy link
Contributor

junyu-w commented Nov 4, 2016

@tansaku I talked with @Shuotong and we think it's probably better to merge this code in first and then he'll assign himself some refactoring tickets during next iteration.. since our next customer meeting is the coming monday and we'd like to show this feature :) Thanks!

@tansaku
Copy link
Contributor

tansaku commented Nov 4, 2016

@DrakeW reasonable point - although can you not show the feature on the cs169 server?

@junyu-w
Copy link
Contributor

junyu-w commented Nov 4, 2016

@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?

@tansaku
Copy link
Contributor

tansaku commented Nov 4, 2016

@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

@armandofox
Copy link
Contributor

armandofox commented Nov 4, 2016

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

@tansaku
Copy link
Contributor

tansaku commented Nov 4, 2016

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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file shouldn't be changed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure - which file are you referring to? sorry ... you mean the README? a codeclimate file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean the README, this line is our repo's code climate coverage badge

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, being changes from build to coverage - we should display both right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late comment, been busy with other stuff recently..

and @Shuotong can you update this readme to not remove the coverage badge and update this branch according to @tansaku 's comments days ago? Thanks

@tansaku
Copy link
Contributor

tansaku commented Nov 15, 2016

@Shuotong looking forward to updates on this

@tansaku
Copy link
Contributor

tansaku commented Nov 22, 2016

Thanks @Shuotong - big step forward. I've made a few cosmetic changes to standardize indentation and spacing after commas, as well as renaming existed_configs to existing_configs which I think makes more sense grammatically.

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
  end

to 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
end

and 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?

@tansaku
Copy link
Contributor

tansaku commented Nov 23, 2016

@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

@junyu-w
Copy link
Contributor

junyu-w commented Nov 29, 2016

@tansaku I agree with what you proposed above. And @Shuotong is not back yet from his thanksgiving trip so I'm not sure when he can put hands on it. But we can definitely open a refactor ticket

@Shuotong
Copy link
Author

Shuotong commented Dec 1, 2016

@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.

@tansaku
Copy link
Contributor

tansaku commented Dec 1, 2016

@Shuotong @DrakeW that's great - can you paste in links to features and refactoring tickets for future reference? thanks :-)

@tansaku
Copy link
Contributor

tansaku commented Dec 1, 2016

was just running this branch on the develop server and I notice that the code climate element is asking for channel and token:

some local fail - or possibly the gem reporting the wrong set of requirements?

@tansaku
Copy link
Contributor

tansaku commented Dec 1, 2016

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 space indenting please - let's be consistent :-)

@tansaku
Copy link
Contributor

tansaku commented Dec 2, 2016

@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 ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants