Skip to content

Commit

Permalink
add checks to controller spec
Browse files Browse the repository at this point in the history
  • Loading branch information
ElviaBth committed Apr 18, 2024
1 parent 7c28397 commit 3de8de9
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions spec/controller/admin/codes_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,36 @@ module Admin
routes { Decidim::AnonymousCodes::AdminEngine.routes }
let(:current_user) { create(:user, :confirmed, :admin, organization: current_organization) }
let(:current_organization) { create(:organization) }
let(:component) { survey.component }
let!(:survey) { create(:survey) }
let!(:existing_group) { create(:anonymous_codes_group, title: { en: "Existing group" }, organization: organization, resource: survey) }
let!(:existing_empty_group) { create(:anonymous_codes_group, title: { en: "Existing empty group" }, organization: organization, resource: survey) }
let!(:anonymous_codes_token1) { create(:anonymous_codes_token, group: existing_group) }
let!(:anonymous_codes_token2) { create(:anonymous_codes_token, :used, group: existing_group) }
let!(:group) { create(:anonymous_codes_group, expires_at: 1.day.from_now, active: true, max_reuses: 10, organization: current_organization) }

before do
request.env["decidim.current_organization"] = current_organization
sign_in current_user, scope: :user
end

describe "GET #index" do
let!(:token1) { Token.create(group: group, created_at: 2.days.ago) }
let!(:token2) { Token.create(group: group, created_at: 1.day.ago) }

it "enforces permission to view anonymous code tokens" do
expect(controller).to receive(:enforce_permission_to).with(:view, :anonymous_code_token)
get :index, params: { code_group_id: code_group.id }
end

it "assigns @tokens with paginated tokens ordered by creation date" do
token1
token2

get :index, params: { code_group_id: code_group.id }

expect(assigns(:tokens)).to eq([token2, token1])
end

it "renders the index template" do
get :index, params: { code_group_id: code_group.id }
expect(response).to render_template(:index)
end
end
end
end
end
Expand Down

0 comments on commit 3de8de9

Please sign in to comment.