-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed the n+1 issue and installed rspec
- Loading branch information
1 parent
5d72ec4
commit f7a8a47
Showing
34 changed files
with
440 additions
and
241 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
--require spec_helper |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
class ApplicationController < ActionController::Base | ||
before_action :configure_permitted_parameters, if: :devise_controller? | ||
before_action :configure_permitted_parameters, if: :devise_controller? | ||
|
||
protected | ||
def configure_permitted_parameters | ||
devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) | ||
end | ||
protected | ||
|
||
def configure_permitted_parameters | ||
devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) | ||
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 |
---|---|---|
@@ -1,58 +1,57 @@ | ||
class GroupsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def index | ||
@groups = Group.all | ||
end | ||
before_action :authenticate_user! | ||
|
||
def new | ||
@group = Group.new | ||
end | ||
def index | ||
@groups = Group.all | ||
end | ||
|
||
def show | ||
@group = current_user.groups.find(params[:id]) | ||
@transaction = @group.transactions | ||
@total = @transaction.sum(:amount) | ||
end | ||
def new | ||
@group = Group.new | ||
end | ||
|
||
def create | ||
@group = current_user.groups.new(fields_arr) | ||
def show | ||
@group = current_user.groups.find(params[:id]) | ||
@transaction = @group.transactions | ||
@total = @transaction.sum(:amount) | ||
end | ||
|
||
if @group.save | ||
def create | ||
@group = current_user.groups.new(fields_arr) | ||
|
||
redirect_to groups_path | ||
else | ||
render :new | ||
if @group.save | ||
|
||
end | ||
end | ||
redirect_to groups_path | ||
else | ||
render :new | ||
|
||
def edit | ||
@group = current_user.groups.find(params[:id]) | ||
end | ||
end | ||
|
||
def update | ||
@group = current_user.groups.find(params[:id]) | ||
if @group.update(fields_arr) | ||
def edit | ||
@group = current_user.groups.find(params[:id]) | ||
end | ||
|
||
def update | ||
@group = current_user.groups.find(params[:id]) | ||
if @group.update(fields_arr) | ||
|
||
redirect_to groups_path, notice: 'Group was successfully updated.' | ||
else | ||
render :edit | ||
end | ||
redirect_to groups_path, notice: 'Group was successfully updated.' | ||
else | ||
render :edit | ||
end | ||
end | ||
|
||
# DELETE /groups/1.json | ||
# DELETE /groups/1.json | ||
def destroy | ||
@group = current_user.groups.find(params[:id]) | ||
@group.destroy | ||
redirect_back(fallback_location: root_path) | ||
|
||
redirect_back(fallback_location: root_path) | ||
end | ||
|
||
private | ||
private | ||
|
||
def fields_arr | ||
params.require(:group).permit(:name, :icon) | ||
end | ||
def fields_arr | ||
params.require(:group).permit(:name, :icon) | ||
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 |
---|---|---|
@@ -1,17 +1,16 @@ | ||
class StaticPagesController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def home | ||
end | ||
before_action :authenticate_user! | ||
|
||
def external | ||
user = User.find_by(id: current_user.id) | ||
@external_user_transactions = user.transactions.where(group_id: nil).order(created_at: :desc) | ||
@external_total = @external_user_transactions.sum(:amount) | ||
end | ||
|
||
def friends | ||
@users = User.where.not(id: current_user.id) | ||
@expenses = Transaction.where.not(user_id: current_user.id).all | ||
end | ||
def home; end | ||
|
||
def external | ||
user = User.find_by(id: current_user.id) | ||
@external_user_transactions = user.transactions.where(group_id: nil).order(created_at: :desc) | ||
@external_total = @external_user_transactions.sum(:amount) | ||
end | ||
|
||
def friends | ||
@users = User.where.not(id: current_user.id) | ||
@expenses = Transaction.where.not(user_id: current_user.id).all | ||
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 |
---|---|---|
@@ -1,82 +1,73 @@ | ||
class TransactionsController < ApplicationController | ||
before_action :authenticate_user! | ||
|
||
def index | ||
@transaction = current_user.transactions.all | ||
@other_transaction = @transaction.where.not(group_id: nil) | ||
@other_transaction_sorted = @other_transaction.sort_by(&:created_at).reverse | ||
|
||
@total = @other_transaction.sum(:amount) | ||
|
||
end | ||
before_action :authenticate_user! | ||
|
||
def new | ||
@transaction = Transaction.new | ||
end | ||
def index | ||
@transaction = current_user.transactions.all | ||
@other_transaction = @transaction.where.not(group_id: nil) | ||
@other_transaction_sorted = @other_transaction.includes([:group]).sort_by(&:created_at).reverse | ||
|
||
def create | ||
@total = @other_transaction.sum(:amount) | ||
end | ||
|
||
@transaction = current_user.transactions.new(transaction_params) | ||
def new | ||
@transaction = Transaction.new | ||
end | ||
|
||
if @transaction.save | ||
|
||
if @transaction.group_id.nil? | ||
def create | ||
@transaction = current_user.transactions.new(transaction_params) | ||
|
||
redirect_to external_path, notice: 'Transaction expense was successfully created.' | ||
if @transaction.save | ||
|
||
else | ||
if @transaction.group_id.nil? | ||
|
||
redirect_to transactions_path, notice: 'Transaction was successfully created.' | ||
redirect_to external_path, notice: 'Transaction expense was successfully created.' | ||
|
||
else | ||
|
||
end | ||
redirect_to transactions_path, notice: 'Transaction was successfully created.' | ||
|
||
else | ||
end | ||
|
||
render :new | ||
else | ||
|
||
end | ||
end | ||
render :new | ||
|
||
def show | ||
@transaction = Transaction.find(params[:id]) | ||
end | ||
end | ||
|
||
def edit | ||
def show | ||
@transaction = Transaction.find(params[:id]) | ||
end | ||
|
||
@transaction = current_user.transactions.find(params[:id]) | ||
end | ||
def edit | ||
@transaction = current_user.transactions.find(params[:id]) | ||
end | ||
|
||
def update | ||
@transaction = current_user.transactions.find(params[:id]) | ||
if @transaction.update(transaction_params) | ||
|
||
if @transaction.group_id.nil? | ||
|
||
redirect_to external_path, notice: 'external transaction was successfully updated.' | ||
else | ||
redirect_to transactions_path, notice: 'transaction was successfully updated.' | ||
end | ||
|
||
|
||
def update | ||
@transaction = current_user.transactions.find(params[:id]) | ||
if @transaction.update(transaction_params) | ||
|
||
if @transaction.group_id.nil? | ||
|
||
redirect_to external_path, notice: 'external transaction was successfully updated.' | ||
else | ||
render :edit | ||
redirect_to transactions_path, notice: 'transaction was successfully updated.' | ||
end | ||
end | ||
|
||
def destroy | ||
|
||
else | ||
render :edit | ||
end | ||
end | ||
|
||
def destroy | ||
@transaction = current_user.transactions.find(params[:id]) | ||
@transaction.destroy | ||
redirect_back(fallback_location: root_path) | ||
redirect_back(fallback_location: root_path) | ||
end | ||
|
||
|
||
end | ||
|
||
private | ||
private | ||
|
||
def transaction_params | ||
params.require(:transaction).permit(:name, :amount, :group_id) | ||
end | ||
|
||
def transaction_params | ||
params.require(:transaction).permit(:name, :amount, :group_id) | ||
end | ||
end |
Oops, something went wrong.