Skip to content
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

Added fast switch option #1806

Merged
merged 13 commits into from May 18, 2018
Merged

Conversation

AmitJoki
Copy link
Contributor

@AmitJoki AmitJoki commented Mar 16, 2018

Fixes #1804

Use in application.yml

  wiki_education: 'true'  # or false for P & E Dashboard

@AmitJoki
Copy link
Contributor Author

AmitJoki commented Mar 16, 2018

@ragesoss this build will most probably fail because it needs to add a key to the application.yml and I can't because it is in the .gitignore. So could you please add the key manually?

def self.disable_help?
ENV['disable_help'] == 'true'
PE.each do |method|
define_singleton_method method do
Copy link
Member

@ragesoss ragesoss Mar 16, 2018

Choose a reason for hiding this comment

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

I would rather not do this with metaprogramming. Repeating ENV['wiki_education'] == 'true' isn't a big deal, and will keep the code extremely transparent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did that first but it felt weird to have the same code repeated many times. Also thought since we are whitelisting the methods, there wouldn't be anything to worry about. But your point seems fair. Have refactored like you asked.

@ragesoss
Copy link
Member

@AmitJoki you can add the ENV value to config/environments/test.rb

@AmitJoki
Copy link
Contributor Author

@ragesoss this build is failing due to some VCR error. Can you please rebuild this?

@ragesoss
Copy link
Member

@AmitJoki that doesn't look like an error that will fix itself. I'll rebuild just to be sure, but I think it's related to this PR.

@AmitJoki
Copy link
Contributor Author

@ragesoss you're right that this PR is causing it. It is failing locally for me too. But, the features.rb is replicating whatever the earlier one with lots of ENV variables was doing. So, I can't fathom why this is causing the build to break. Will check into it and if you could nitpick any cause for the error, it would be great in the meantime :)

@ragesoss
Copy link
Member

The error looks like it's related to the wiki trainings feature being enabled at some place in the code where it was not previously.

@@ -33,10 +37,6 @@ def self.enable_account_requests?
ENV['wiki_education'] != 'true'
end

def self.wiki_trainings?
ENV['wiki_education'] != 'true'
Copy link
Member

Choose a reason for hiding this comment

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

This was correct. Wiki trainings should be enabled with it's not wiki ed.

@@ -5,6 +5,7 @@
ENV['open_course_creation'] = 'false'
ENV['course_prefix'] = 'Wikipedia:Wiki_Ed'
ENV['wiki_language'] = 'en'
ENV['wiki_education'] = 'false'
Copy link
Member

Choose a reason for hiding this comment

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

This should be true.

Copy link
Member

Choose a reason for hiding this comment

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

You can also remove the ENV values in this file that are no longer used in Features.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got more errors when I had that true hence put false out there. Will change and delete the redundant ENV variables.

@@ -7,7 +7,7 @@
describe '.wiki_ed?' do
context 'when the url is dashboard-testing.wikiedu.org' do
before do
allow(ENV).to receive(:[]).with('dashboard_url').and_return('dashboard-testing.wikiedu.org')
allow(ENV).to receive(:[]).with('wiki_education').and_return('true')
Copy link
Member

Choose a reason for hiding this comment

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

You can either change the 'context' description for these, or delete them altogether. After this change, they no longer test anything useful.

@AmitJoki
Copy link
Contributor Author

@ragesoss see the build? I have no idea why it is failing and the logs have not been helping out either. I have returned values in accordance with your comment on the issue #1804. Can you please look into it?

@ragesoss
Copy link
Member

ragesoss commented Mar 20, 2018

Most or all of these are probably cases where the test environment previous was configured in a way that didn't match either of the two main environments. Features were enabled based on convenience of testing, and now those features are disabled.

For example, the RequestedAccountsController spec is written based on the default of Features.enable_account_requests? being true, even though it is false on Wiki Education production. To fix that spec, we'll need to do before { allow(Features).to receive(:enable_account_requests?).and_return(false) } at the top of the spec. The others should mostly have similar solutions.

@AmitJoki
Copy link
Contributor Author

@ragesoss that explains a lot. Thanks.

@AmitJoki
Copy link
Contributor Author

AmitJoki commented Mar 20, 2018

@ragesoss I tried your suggested method and it didn't seem to have any effect on the outcome. Hence, I've updated the tests to run conditionally.

@AmitJoki
Copy link
Contributor Author

@ragesoss I have no rubocop errors for the file shown in the build logs. Can you please rebuild this one?

@ragesoss
Copy link
Member

This is because of the new release of rubocop 0.54; the lastest version gets installed and run by travis. I'm fixing this today.

Copy link
Member

@ragesoss ragesoss left a comment

Choose a reason for hiding this comment

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

The conditional specs approach will result in never running those tests, since the test environment is set for the wiki_ed config by default. We need to tweak the tests so that they will still test everything.

ENV['wiki_education'] != 'true'
end

def self.disable_help?
Copy link
Member

Choose a reason for hiding this comment

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

This one shows up three times.

end

def self.open_course_creation?
ENV['open_course_creation'] == 'true'
def self.disable_wiki_output?
Copy link
Member

Choose a reason for hiding this comment

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

This should keep its old definition. Wiki output is currently enabled on both dashboard (and is usually disabled in dev environments).

ENV['default_course_type'] = 'ClassroomProgramCourse'
ENV['open_course_creation'] = 'false'
ENV['disable_wiki_output'] = 'false'
Copy link
Member

Choose a reason for hiding this comment

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

Keep this.

it 'renders' do
get :index
expect(response.status).to eq(200)
if Features.enable_article_finder?
Copy link
Member

Choose a reason for hiding this comment

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

Instead of skipping these tests, you should do allow(Features).to receive(:enable_article_finder?).and_return(true) in a before block.

post :create_accounts, params: { campaign_slug: campaign.slug }
expect(response.status).to eq(200)
expect(RequestedAccount.count).to eq(0)
if Features.enable_account_requests?
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here; use allow to turn the feature on for these tests, rather than skip the tests.

let(:username) { 'username' }
let(:email) { 'valid@example.com' }

if Features.enable_account_requests?
Copy link
Member

Choose a reason for hiding this comment

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

Same.

@@ -5,22 +5,13 @@

describe Features do
describe '.wiki_ed?' do
context 'when the url is dashboard-testing.wikiedu.org' do
Copy link
Member

Choose a reason for hiding this comment

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

This whole spec file can probably just be deleted, since the implementation is now trivial.

ragesoss added a commit that referenced this pull request May 18, 2018
…t toggles

This should fix the code review comments from PR #1806
@ragesoss ragesoss merged commit b0c3477 into WikiEducationFoundation:master May 18, 2018
@ragesoss
Copy link
Member

thanks @AmitJoki! I finished this up and merged it.

@AmitJoki
Copy link
Contributor Author

@ragesoss glad you could patch it up 😃

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.

None yet

2 participants