-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated test cases in csv_controller_spec.rb and ensured passed, incl…
…uded test.csv for testing purposes
- Loading branch information
1 parent
3fd9d50
commit 1896e6a
Showing
3 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,7 @@ | |
describe '#current_user' do | ||
context 'when session contains user_id' do | ||
before do | ||
@user = User.create!(uid: '12345', provider: 'google_oauth2', email: '[email protected]', first_name: 'John', | ||
last_name: 'Doe') | ||
@user = User.create!(uid: '12345', provider: 'google_oauth2', email: '[email protected]', first_name: 'John', last_name: 'Doe') | ||
session[:user_id] = @user.id | ||
puts "session[:user_id] = #{session[:user_id]}" | ||
end | ||
|
@@ -32,8 +31,7 @@ | |
describe '#logged_in?' do | ||
context 'when user is logged in' do | ||
before do | ||
@user = User.create!(uid: '12345', provider: 'google_oauth2', email: '[email protected]', first_name: 'John', | ||
last_name: 'Doe') | ||
@user = User.create!(uid: '12345', provider: 'google_oauth2', email: '[email protected]', first_name: 'John', last_name: 'Doe') | ||
session[:user_id] = @user.id | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# spec/controllers/csv_controller_spec.rb | ||
require 'rails_helper' | ||
|
||
RSpec.describe CsvController, type: :controller do | ||
before do | ||
# Create a user and set session user_id as done in your application_controller_spec.rb | ||
@user = User.create!(uid: '12345', provider: 'google_oauth2', email: '[email protected]', first_name: 'John', last_name: 'Doe') | ||
session[:user_id] = @user.id | ||
end | ||
|
||
let(:file) { fixture_file_upload(Rails.root.join('spec', 'fixtures', 'files', 'test.csv'), 'text/csv') } | ||
|
||
describe "POST #upload" do | ||
context "with a valid CSV file" do | ||
it "processes the CSV file, sets a success flash, and redirects to the user's page" do | ||
post :upload, params: { csv_file: file } | ||
|
||
expect(response).to have_http_status(:redirect) | ||
expect(response).to redirect_to(user_path(@user)) # Redirect to the current user's page | ||
expect(flash[:notice]).to eq("CSV file uploaded successfully.") | ||
end | ||
end | ||
|
||
context "when no CSV file is selected" do | ||
it "sets an error flash and redirects to the user's page" do | ||
post :upload, params: { csv_file: nil } | ||
|
||
expect(response).to have_http_status(:redirect) | ||
expect(response).to redirect_to(user_path(@user)) # Redirect to the current user's page | ||
expect(flash[:error]).to eq("Please upload a CSV file.") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Name,Age,Occupation | ||
Alice,25,Engineer | ||
Bob,30,Doctor | ||
Charlie,35,Artist | ||
Diana,40,Scientist |