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

User based experiment: create end points and tests #22193

Merged
merged 3 commits into from
May 4, 2018
Merged

Conversation

caleybrock
Copy link
Contributor

@caleybrock caleybrock commented May 4, 2018

Step 1 in 2018 teacher experience flag spec

Users will be able to join and leave an experiment via link (and experiment will be saved to their account)

  • Use experiment.rb model/table
  • Rows will be a single_user_experiment
  • Expose an API that allows the current user to join a given experiment
  • Experiment should expire after a month by default
  • Expose an API that allows the current user to remove themselves for an experiment

Success message will be on studio home page and looks like this:
screen shot 2018-05-03 at 6 56 10 pm

This sets us up to have a single flag for all the 2018 teacher experience work that will only need to be set once and will work on pegasus and dashboard.

cc @Erin007 @nkiruka


# GET /experiments/set_single_user_experiment/:experiment_name
def set_single_user_experiment
valid_experiments = ['2018-teacher-experience']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

is there a better place for this constant?

Copy link
Member

Choose a reason for hiding this comment

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

it would be more standard to define it on the class:

  VALID_EXPERIMENTS = [...]

  # ...
  def set_single_user_experiment

Copy link
Member

@davidsbailey davidsbailey left a comment

Choose a reason for hiding this comment

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

👍


# GET /experiments/set_single_user_experiment/:experiment_name
def set_single_user_experiment
valid_experiments = ['2018-teacher-experience']
Copy link
Member

Choose a reason for hiding this comment

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

it would be more standard to define it on the class:

  VALID_EXPERIMENTS = [...]

  # ...
  def set_single_user_experiment

def disable_single_user_experiment
experiment_name = params[:experiment_name]

unless Experiment.enabled?(experiment_name: experiment_name, user: current_user)
Copy link
Member

Choose a reason for hiding this comment

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

optional: could be nice to first warn if the experiment is not valid again, to get a better error message in case of accidentally truncated urls


test_user_gets_response_for(
:disable_single_user_experiment,
name: 'single user cannot set disable experiment they are not in',
Copy link
Member

Choose a reason for hiding this comment

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

cannot set disable experiment

assert_nil flash[:alert]
assert_includes flash[:notice], "You have successfully disabled the experiment"
assert_nil Experiment.first
end
Copy link
Member

Choose a reason for hiding this comment

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

nice tests!

Copy link
Contributor

@balderdash balderdash left a comment

Choose a reason for hiding this comment

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

LGTM

end

experiment = SingleUserExperiment.where(min_user_id: current_user.id, name: experiment_name).first
experiment.destroy
Copy link
Contributor

Choose a reason for hiding this comment

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

It's possible that the user was in the experiment through another experiment type, in which case experiment would be nil here. If so, maybe show a "Unable to leave experiment X" message.

return
end

experiment = SingleUserExperiment.where(min_user_id: current_user.id, name: experiment_name).first
Copy link
Contributor

Choose a reason for hiding this comment

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

Also where(...).first can just be find_by(...)

@caleybrock
Copy link
Contributor Author

Thanks for the feedback - all suggestions should be updated.

@caleybrock caleybrock merged commit cb91548 into staging May 4, 2018
@caleybrock caleybrock deleted the experiment-api branch May 4, 2018 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants