Skip to content

Commit

Permalink
Add ability to download user lists as CSV
Browse files Browse the repository at this point in the history
* Global and chapter lists can be downloaded as CSV
* Still need to add to the interface
  • Loading branch information
jcn committed Jun 8, 2024
1 parent 128e73b commit 5431e42
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 9 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ class UsersController < ApplicationController
before_action :ensure_current_user_or_admin, :only => [:update, :edit]

def index
@users = User.all_with_chapter(params[:chapter_id]).paginate(page: params[:page], per_page: 250)
@users = User.all_with_chapter(params[:chapter_id])

respond_to do |format|
format.html do
@users = @users.paginate(page: params[:page], per_page: 250)
end
format.csv do
end
end
end

def update
Expand Down
18 changes: 15 additions & 3 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
require 'spec_helper'

describe UsersController do
describe UsersController, type: :controller do
context "signed in as admin user" do
render_views

let(:user) { FactoryGirl.create(:user, :admin => true) }
before do
sign_in_as user
get :index
end
it { is_expected.to respond_with(:success) }

context "fetching an HTML file" do
before { get :index }
it { is_expected.to respond_with(:success) }
it { should render_template("index") }
end

context "fetching a CSV file" do
before { get :index, format: "csv" }
it { is_expected.to respond_with(:success) }
it { should render_template("index") }
end
end
context "signed in as non-admin user" do
let(:role) { FactoryGirl.create(:role) }
Expand Down

0 comments on commit 5431e42

Please sign in to comment.