spec/flipper/ui/actions/groups_gate_spec.rb in flipper-ui-0.10.1 vs spec/flipper/ui/actions/groups_gate_spec.rb in flipper-ui-0.10.2
- old
+ new
@@ -34,10 +34,12 @@
expect(last_response.body).to include('<form action="/features/search/groups" method="post">')
end
end
describe "POST /features/:feature/groups" do
+ let(:group_name) { "admins" }
+
before do
Flipper.register(:admins) { |user| user.admin? }
end
after do
@@ -45,11 +47,11 @@
end
context "enabling a group" do
before do
post "features/search/groups",
- {"value" => "admins", "operation" => "enable", "authenticity_token" => token},
+ {"value" => group_name, "operation" => "enable", "authenticity_token" => token},
"rack.session" => session
end
it "adds item to members" do
expect(flipper[:search].groups_value).to include("admins")
@@ -57,17 +59,56 @@
it "redirects back to feature" do
expect(last_response.status).to be(302)
expect(last_response.headers["Location"]).to eq("/features/search")
end
+
+ context 'group name contains whitespace' do
+ let(:group_name) { " admins " }
+
+ it "adds item without whitespace" do
+ expect(flipper[:search].groups_value).to include("admins")
+ end
+ end
+
+ context "for an unregistered group" do
+ context "unknown group name" do
+ let(:group_name) { "not_here" }
+
+ it "redirects back to feature" do
+ expect(last_response.status).to be(302)
+ expect(last_response.headers["Location"]).to eq("/features/search/groups?error=The+group+named+%22not_here%22+has+not+been+registered.")
+ end
+ end
+
+ context "empty group name" do
+ let(:group_name) { "" }
+
+ it "redirects back to feature" do
+ expect(last_response.status).to be(302)
+ expect(last_response.headers["Location"]).to eq("/features/search/groups?error=The+group+named+%22%22+has+not+been+registered.")
+ end
+ end
+
+ context "nil group name" do
+ let(:group_name) { nil }
+
+ it "redirects back to feature" do
+ expect(last_response.status).to be(302)
+ expect(last_response.headers["Location"]).to eq("/features/search/groups?error=The+group+named+%22%22+has+not+been+registered.")
+ end
+ end
+ end
end
context "disabling a group" do
+ let(:group_name) { "admins" }
+
before do
flipper[:search].enable_group :admins
post "features/search/groups",
- {"value" => "admins", "operation" => "disable", "authenticity_token" => token},
+ {"value" => group_name, "operation" => "disable", "authenticity_token" => token},
"rack.session" => session
end
it "removes item from members" do
expect(flipper[:search].groups_value).not_to include("admins")
@@ -75,21 +116,16 @@
it "redirects back to feature" do
expect(last_response.status).to be(302)
expect(last_response.headers["Location"]).to eq("/features/search")
end
- end
- context "for an unregistered group" do
- before do
- post "features/search/groups",
- {"value" => "not_here", "operation" => "enable", "authenticity_token" => token},
- "rack.session" => session
- end
+ context 'group name contains whitespace' do
+ let(:group_name) { " admins " }
- it "redirects back to feature" do
- expect(last_response.status).to be(302)
- expect(last_response.headers["Location"]).to eq("/features/search/groups?error=The+group+named+%22not_here%22+has+not+been+registered.")
+ it "removes item without whitespace" do
+ expect(flipper[:search].groups_value).not_to include("admins")
+ end
end
end
end
end