File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33module Api
44 class FeaturesController < ApiController
55 def index
6- features = Flipper . features . map do |feature |
7- [ feature . key , Flipper . enabled? ( feature . key , current_user &.schools &.first ) ]
8- end
6+ school = current_user &.schools &.first
97
10- render json : features . to_h
8+ enabled_feature_keys = Flipper . features
9+ . select { |feature | Flipper . enabled? ( feature . key , school ) }
10+ . map { |feature | feature . key }
11+
12+ render json : enabled_feature_keys
1113 end
1214 end
1315end
Original file line number Diff line number Diff line change 1919 get "/api/features"
2020
2121 # Assert
22- expect ( response . body ) . not_to include ( '" some_global_feature":true ' )
22+ expect ( response . body ) . not_to include ( 'some_global_feature' )
2323 end
2424
2525 it "returns a globally-enabled feature as enabled" do
3030 get "/api/features"
3131
3232 # Assert
33- expect ( response . body ) . to include ( '" some_global_feature":true ' )
33+ expect ( response . body ) . to include ( 'some_global_feature' )
3434 end
3535
3636 it "returns a school-level feature as disabled for logged-out user" do
4141 get "/api/features"
4242
4343 # Assert
44- expect ( response . body ) . not_to include ( '" some_school_level_feature":true ' )
44+ expect ( response . body ) . not_to include ( 'some_school_level_feature' )
4545 end
4646
4747 it "returns a school-level feature as enabled for a student in that school" do
5454 get "/api/features" , headers : headers
5555
5656 # Assert
57- expect ( response . body ) . to include ( '" some_school_level_feature":true ' )
57+ expect ( response . body ) . to include ( 'some_school_level_feature' )
5858 end
5959
6060 it "returns both school-level and global features as enabled for a student in a school" do
6868 get "/api/features" , headers : headers
6969
7070 # Assert
71- expect ( response . body ) . to include ( '" some_school_level_feature":true ' )
72- expect ( response . body ) . to include ( '" some_global_feature":true ' )
71+ expect ( response . body ) . to include ( 'some_school_level_feature' )
72+ expect ( response . body ) . to include ( 'some_global_feature' )
7373 end
74-
75- # todo: Don't leak the existence of disabled feature flags
76-
7774 end
7875
7976 describe "Feature flag web interface" do
You can’t perform that action at this time.
0 commit comments