Skip to content

Commit

Permalink
Merge pull request #152 from jnunemaker/add_feature_endpoint
Browse files Browse the repository at this point in the history
POST /api/v1/features - add feature endpoint
  • Loading branch information
greatuserongithub authored Aug 22, 2016
2 parents a624a81 + 27b5951 commit cb0f2d0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 20 deletions.
13 changes: 13 additions & 0 deletions lib/flipper/api/v1/actions/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ def get
features: features
})
end

def post
feature_name = params.fetch('name') do
json_response({
errors: [{
message: 'Missing post parameter: name',
}]
}, 422)
end

flipper.adapter.add(flipper[feature_name])
json_response({}, 200)
end
end
end
end
Expand Down
76 changes: 56 additions & 20 deletions spec/flipper/api/v1/actions/features_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@
"name"=> "boolean",
"value" => true},
{
"key" =>"groups",
"name" => "group",
"value" =>[],
},
{
"key" => "actors",
"name"=>"actor",
"value"=>["10"],
},
{
"key" => "percentage_of_actors",
"name" => "percentage_of_actors",
"value" => 0,
},
{
"key"=> "percentage_of_time",
"name"=> "percentage_of_time",
"value"=> 0,
},
],
"key" =>"groups",
"name" => "group",
"value" =>[],
},
{
"key" => "actors",
"name"=>"actor",
"value"=>["10"],
},
{
"key" => "percentage_of_actors",
"name" => "percentage_of_actors",
"value" => 0,
},
{
"key"=> "percentage_of_time",
"name"=> "percentage_of_time",
"value"=> 0,
},
],
},
]
}
Expand All @@ -67,4 +67,40 @@
end
end
end

describe 'post' do
context 'succesful request' do
before do
post 'api/v1/features', { name: 'my_feature' }
end

it 'responds 200 on success' do
expect(last_response.status).to eq(200)
expect(json_response).to eq({})
end

it 'adds feature' do
expect(flipper.features.map(&:key)).to include('my_feature')
end

it 'does not enable feature' do
expect(flipper['my_feature'].enabled?).to be_falsy
end
end

context 'bad request' do
before do
post 'api/v1/features'
end

it 'returns correct status code' do
expect(last_response.status).to eq(422)
end

it 'returns formatted error' do
errors = json_response['errors']
expect(errors.first['message']).to eq('Missing post parameter: name')
end
end
end
end

0 comments on commit cb0f2d0

Please sign in to comment.