houdini/spec/controllers/concerns/supporter/current_spec.rb

48 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

2021-02-24 18:27:48 +00:00
# frozen_string_literal: true
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
require 'rails_helper'
describe 'Controllers::Supporter::Current', type: :controller do
2021-02-24 18:27:48 +00:00
let(:nonprofit) { force_create(:nm_justice) }
let(:supporter) { force_create(:supporter) }
2021-02-24 18:27:48 +00:00
controller(ApplicationController) do
include Controllers::User::Authorization
include Controllers::Supporter::Current
def index
render json: {
2021-02-24 18:27:48 +00:00
supporter: "supporters: #{current_supporter.id}",
nonprofit: "nonprofit: #{current_nonprofit.id}"
}
end
end
2021-02-24 18:27:48 +00:00
it 'handles situations where we use id' do
nonprofit
supporter
2021-02-24 18:27:48 +00:00
get :index, params: { nonprofit_id: nonprofit.id, id: supporter.id }
expect(JSON.parse(response.body)).to eq(
{
'supporter' => "supporters: #{supporter.id}",
'nonprofit' => "nonprofit: #{nonprofit.id}"
}
)
end
2021-02-24 18:27:48 +00:00
it 'handles situations where we use supporter_id' do
nonprofit
supporter
2021-02-24 18:27:48 +00:00
get :index, params: { nonprofit_id: nonprofit.id, supporter_id: supporter.id, id: 1 }
expect(JSON.parse(response.body)).to eq(
{
'supporter' => "supporters: #{supporter.id}",
'nonprofit' => "nonprofit: #{nonprofit.id}"
}
)
end
2021-02-24 18:27:48 +00:00
end