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

Feature flag #10

Open
byhbt opened this issue Jul 15, 2020 · 2 comments
Open

Feature flag #10

byhbt opened this issue Jul 15, 2020 · 2 comments
Labels
Production Release code to production server Ruby Learning Ruby on Rails Testing RSpec/Unit test....

Comments

@byhbt
Copy link
Owner

byhbt commented Jul 15, 2020

Problem:

When release new features, however the customer want hide it for some purpose:

  • Testing
  • For specific user
  • Event days

Solution:

Define variable in env.
Use that flag to control the logic.

NEW_REGISTRATION_ENABLED: false
AWESOME_FEATURE_ENABLED: false

Lesson:

https://jeroenmols.com/blog/2019/08/13/featureflags

@byhbt byhbt self-assigned this Jul 15, 2020
@byhbt byhbt added this to the First 50 issues milestone Jul 15, 2020
@byhbt byhbt removed their assignment Jul 15, 2020
@byhbt
Copy link
Owner Author

byhbt commented Jul 16, 2020

How to test feature flag:

For example, we have a route: /sign-up.

Now we have to replace the existing logic code base by another login.

SignUpController will be replaced by NewSignUpController

The problem: there is one route, in the test environment it will be failed. We still have to write test for the new code base, also keep the existing same code base and specs.

Solution:

require 'rails_helper'

RSpec.describe SignUpsController, type: :controller do
  before do
    @request.env['devise.mapping'] = Devise.mappings[:user]

    Rails.application.routes.draw do
      devise_for :users, controllers: { registrations: 'new_sign_ups' }
    end
  end

  describe 'GET#new' do
    it 'renders new view' do
      get :new

      expect(response).to have_http_status :ok
      expect(response).to render_template :new
    end
  end

  after do
    Rails.application.reload_routes!
  end
end

@byhbt
Copy link
Owner Author

byhbt commented Jul 16, 2020

Why we need mapping:

@request.env['devise.mapping'] = Devise.mappings[:user]

est.env["devise

@byhbt byhbt added Ruby Learning Ruby on Rails Production Release code to production server Testing RSpec/Unit test.... labels Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Production Release code to production server Ruby Learning Ruby on Rails Testing RSpec/Unit test....
Projects
None yet
Development

No branches or pull requests

1 participant