diff --git a/README.md b/README.md index 8ba7620..d54f67a 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,9 @@ bundle exec rake db:create # To create the database bundle exec rake db:migrate # To run the migrations +bundle exec rake db:seed #to run the seed file. + bundle exec rails s # Start the rails server. + Open 'http://localhost:3000' in your browser. diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 1a1f2b0..a2d6ea1 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -16,5 +16,6 @@ //= require bootstrap-sprockets //= require cocoon //= require daily_log +//= require edit_log diff --git a/app/assets/javascripts/daily_log.js b/app/assets/javascripts/daily_log.js index 17d779c..30f5aa7 100644 --- a/app/assets/javascripts/daily_log.js +++ b/app/assets/javascripts/daily_log.js @@ -1,58 +1,76 @@ -function DailyLog() { - $(document).ready(function() { - var add_task = $(".add_field_button"); - $(add_task).click(function(e){ - $('.task').append("
") - +function DailyLog() { + $(document).delegate('.add_field_button', 'click', function() + { + var project_id= $(this).parent().parent().children().eq(0).val(); + $(this).parent().children().eq(1).append("
"); }); - - var add_project = $(".add_project_button"); - $(add_project).click(function(e){ - $('.project').append("

Task

"); - var attrid="projects[]"; - $('.added').attr('name', attrid).append($('#projects_').html()); + $(document).delegate('.add_project_button', 'click', function() + { + $('.project').append("

Task

"); + var attrid="projects[]"; + $('.newproject').attr('name',attrid).append($('#projects_').html()); + $('.newproject').removeClass('newproject'); }); - $('input[name="daterange"]').daterangepicker(); -}); -$('input[name="daterange"]').on('apply.daterangepicker', function(ev, picker) { - var project_id= $("#projects_filter").val(); -$('.user_summary').load('/daily_logs/user_logs',{ start_date: picker.startDate.format('YYYY-MM-DD'), end_date: picker.endDate.format('YYYY-MM-DD'),"project_id": project_id}); -}); -$('select').change(alert_me_test); -function alert_me_test(){ - var project_id= $("#projects_filter").val(); -$('.user_summary').load('/daily_logs/user_logs',{"project_id": project_id}); -} -$('#context1 .menu .item') - .tab({ - context: $('#context1') - }) -; -var today = new Date(); -$('#example1').calendar({ - onChange: function (date, text) { - var newValue = text; - $('.dynamic').load('/daily_logs/refresh',{ "log_date":newValue}); - }, - type: 'date', - maxDate: new Date(today.getFullYear(), today.getMonth(), today.getDate()) - }) -$('.top.menu .item').tab({'onVisible':function(){ - var newValue = $(this).attr("dataval") - $('.dynamic').load('/daily_logs/refresh',{ "log_date":newValue}); -}}); -$('.imageclass').on('click',function(){ - var userid=$(this).attr("id"); - $('.user_list').load('/daily_logs/user_logs',{"user_id":userid}); -}); - + $(document).ready(function() { + $('input[name="daterange"]').daterangepicker(); + }); + $('input[name="daterange"]').on('apply.daterangepicker', function(ev, picker) { + var project_id= $("#projects_filter").val(); + $('.user_summary').load('/daily_logs/user_logs',{ start_date: picker.startDate.format('YYYY-MM-DD'), end_date: picker.endDate.format('YYYY-MM-DD'),"project_id": project_id}); + }); + $('.projects_filter').change(alert_me_test); + function alert_me_test(){ + var project_id= $("#projects_filter").val(); + var datepicker = $('input[name="daterange"]').data('daterangepicker'); + var today=moment().format('DD-MMM-YYYY'); + if(datepicker.startDate.format('DD-MMM-YYYY')==today) + { + $('.user_summary').load('/daily_logs/user_logs',{"project_id": project_id}); + } + else + { + $('.user_summary').load('/daily_logs/user_logs',{start_date:datepicker.startDate.format('YYYY-MM-DD'),end_date:datepicker.endDate.format('YYYY-MM-DD'),"project_id": project_id}); + } + } + $('#context1 .menu .item') + .tab({ + context: $('#context1') + }) + ; + var today = new Date(); + $('#example1').calendar({ + onChange: function (date, text) { + var newValue = text; + $('.dynamic').load('/daily_logs/refresh',{ "log_date":newValue}); + }, + type: 'date', + maxDate: new Date(today.getFullYear(), today.getMonth(), today.getDate()) + }) + $('.top.menu .item').tab({'onVisible':function(){ + // TODO dont you need to put semi colon at EOL + var newValue = $(this).attr("dataval") + $('.dynamic').load('/daily_logs/refresh',{ "log_date":newValue}); + }}); + $('.imageclass').on('click',function(){ + var userid=$(this).attr("id"); + $('.user_list').load('/daily_logs/user_logs',{"user_id":userid}); + }); -$('.secondary.menu .item').tab({'onVisible':function(){ - var x=$(this).attr('data-tab'); - if(x=="first") - location.reload(); + $('.secondary.menu .item').tab({'onVisible':function(){ + // TODO use proper variable names + var x=$(this).attr('data-tab'); + if(x=="first") + location.reload(); -}}) ; + }}) ; + // $('.added').change(function() { + $(document).delegate('.added', 'change', function() + { + var project_id =$(this).val(); + var name= 'log_entry['+project_id+'][]'; + $(this).next().next().next().children().eq(1).children().filter('.form-control').attr('name',name); + $(this).next().next().next().children().filter('.form-control').attr('name',name); + }); }; - + diff --git a/app/assets/javascripts/edit_log.js b/app/assets/javascripts/edit_log.js new file mode 100644 index 0000000..0b666a9 --- /dev/null +++ b/app/assets/javascripts/edit_log.js @@ -0,0 +1,35 @@ +function EditLog() { + $(document).delegate('.add_field_button', 'click', function() + { + var project_id= $(this).parent().parent().children().eq(0).children().val(); + if(project_id=="") + { + var project_id= $(this).parent().parent().children().eq(0).children().attr("value"); + } + $(this).parent().children().eq(0).append("
"); + }); + $(document).delegate('.added', 'change', function() + { + var project_id =$(this).val(); + if(project_id=="") + { + project_id= $(this).attr("value"); + } + var name= 'new_log_entries['+project_id+'][]'; + $(this).parent().parent().children().eq(2).children().eq(0).children().filter('.NewlyAdded').attr('name',name); + $(this).parent().parent().children().eq(2).children().eq(0).children().filter('.existing').each(function(i){ + var oldName= $(this).attr('name'); + var newName='log_entries['+project_id+']'+oldName.substring(oldName.lastIndexOf('[')); + $(this).attr('name',newName); + }); + }); + $(document).delegate('.add_project_button','click',function() + { + var value= $('#projects_').attr('value'); + var attrid ="projects[]" + $('.project').append("
Task

"); + $('.newproject').attr('name',attrid).append($('#projects_').html()); + $('.newproject').removeClass('newproject') + }); +}; + diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index d3ef54f..2ccf76c 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -1,3 +1,4 @@ +// TODO you should put css related different pages in different files // Custom bootstrap variables must be set or imported *before* bootstrap. @import "bootstrap"; @@ -12,15 +13,6 @@ body { margin-bottom: 60px; background-color: #f2f2f2; } -footer { - position: fixed; - bottom: 0; - width: 100%; - /* Set the fixed height of the footer here */ - height: 60px; - line-height: 60px; /* Vertically center the text there */ - background-color: #f5f5f5; -} /* Custom page CSS @@ -31,10 +23,6 @@ body > .container { padding: 60px 15px 0; } -.footer > .container { - padding-right: 15px; - padding-left: 15px; -} code { font-size: 80%; @@ -50,7 +38,11 @@ code { #wrapper.toggled { padding-left: 250px; } - +.task +{ + padding-top:10px; + padding-bottom:5px +} #sidebar-wrapper { z-index: 1000; position: fixed; @@ -64,16 +56,31 @@ code { -moz-transition: all 0.5s ease; -o-transition: all 0.5s ease; transition: all 0.5s ease; + background-color:#394051; } .page { background-color:white; width : 50%; + padding-top:30px; +} +.centeralign +{ + padding-top:9px; } #wrapper.toggled #sidebar-wrapper { width: 250px; } +.headerclass +{ + padding-top:15px; + padding-bottom:5px; +} +.datecolor +{ + color:#55B6AE; +} #page-content-wrapper { width: 100%; @@ -88,7 +95,6 @@ code { } /* Sidebar Styles */ - .sidebar-nav { position: absolute; top: 0; @@ -106,18 +112,18 @@ code { .sidebar-nav li a { display: block; text-decoration: none; - color: #999999; + color:white ; } .sidebar-nav li a:hover { text-decoration: none; - color: #fff; + color: #f0f0f0; background: rgba(255,255,255,0.2); } .sidebar-nav li a:active, .sidebar-nav li a:focus { - color : #ffff; + color : #484848; } a.active { @@ -130,16 +136,16 @@ a.active } .sidebar-nav > .sidebar-brand a { - color: #999999; -} + color: white; + } .sidebar-nav > .sidebar-brand a:hover { color: #fff; background: none; } -input[type="text"] +.form-control { - width:50%; + width:100%; } #reportrange { @@ -149,6 +155,12 @@ input[type="text"] border: 1px solid #ccc; width: 100%; } +#datetime_ida +{ + border-color: #55B6AE; + color: #55b6ae; + background-color: white; +} .pull-right { text-align:right; @@ -156,8 +168,8 @@ input[type="text"] } .btn-default { - border: 2px solid #1aff1a; - color: #1aff1a; + border: 2px solid #45CDC5; + color: #45CDC5; background-color:white; } @@ -165,6 +177,13 @@ input[type="text"] { width:75%; } +.projects_filter +{ + width: 25%; + margin-bottom: 20px; + margin-top: 10px; + height: 35px; + } .imageclass { height: 150px ; @@ -175,4 +194,90 @@ input[type="text"] display: block; margin-left: auto; margin-right: auto; - } +} +.btn-change +{ + background-color:#55B6AE; + border-color:#55B6AE; + color:white; + margin-bottom:20px; + +} +.added +{ + width: 28%; + height: 40px; + background-color: white; + border-color: #E9E9E9; +} +.imagecircle +{ + border-radius: 50%; + width:50px; + height:50px; +} +.btn { /* just for this demo. */ + margin-top: 5px; +} +.btn-arrow-right, +.btn-arrow-left { + position: relative; + padding-left: 18px; + padding-right: 18px; +} +.btn-arrow-right { + padding-left: 20px; +} +.btn-arrow-left { + padding-right: 20px; + height: 12%; +} +.btn-arrow-right:before, +.btn-arrow-right:after, +.btn-arrow-left:before, +.btn-arrow-left:after { /* make two squares (before and after), looking similar to the button */ + content:""; + position: absolute; + top: 5px; /* move it down because of rounded corners */ + width: 22px; /* same as height */ + height: 22px; /* button_outer_height / sqrt(2) */ + background: inherit; /* use parent background */ + border: inherit; /* use parent border */ + border-left-color: transparent; /* hide left border */ + border-bottom-color: transparent; /* hide bottom border */ + border-radius: 0px 4px 0px 0px; /* round arrow corner, the shorthand property doesn't accept "inherit" so it is set to 4px */ + -webkit-border-radius: 0px 4px 0px 0px; + -moz-border-radius: 0px 4px 0px 0px; +} +.btn-arrow-right:before, +.btn-arrow-right:after { + transform: rotate(45deg); /* rotate right arrow squares 45 deg to point right */ + -webkit-transform: rotate(45deg); + -moz-transform: rotate(45deg); + -o-transform: rotate(45deg); + -ms-transform: rotate(45deg); +} +.btn-arrow-left:before, +.btn-arrow-left:after { + transform: rotate(225deg); /* rotate left arrow squares 225 deg to point left */ + -webkit-transform: rotate(225deg); + -moz-transform: rotate(225deg); + -o-transform: rotate(225deg); + -ms-transform: rotate(225deg); +} +.btn-arrow-right:before, +.btn-arrow-left:before { /* align the "before" square to the left */ + left: -11px; +} +.btn-arrow-right:after, +.btn-arrow-left:after { /* align the "after" square to the right */ + right: -11px; +} +.btn-arrow-right:after, +.btn-arrow-left:before { /* bring arrow pointers to front */ + z-index: 0; +} +.btn-arrow-right:before, +.btn-arrow-left:after { /* hide arrow tails background */ + background-color: white; +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4338298..f6c3544 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true class ApplicationController < ActionController::Base + #TODO add authenticate_user in before action protect_from_forgery with: :exception helper_method :current_user @@ -8,4 +9,14 @@ class ApplicationController < ActionController::Base def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] end + #TODO add empty line after evry action + #TODO add authenticate_user in before_action for ApplicationController + def authenticate_user + if (current_user.nil?) + url="/auth/google_oauth2" + #TODO add flash message "please login to continue" + redirect_to(url) + end + end + end diff --git a/app/controllers/daily_logs_controller.rb b/app/controllers/daily_logs_controller.rb index d6a558f..8f91261 100644 --- a/app/controllers/daily_logs_controller.rb +++ b/app/controllers/daily_logs_controller.rb @@ -1,90 +1,72 @@ class DailyLogsController < ApplicationController include DailyLogsHelper skip_before_action :verify_authenticity_token - def new - #@projects=Project.where(client_name: Project::BEAUTIFUL_CODE_CLIENT) - @daily_log =current_user.daily_logs.new - @projects=Project.all - if(!params[:start_date].nil?) - session[:start_date] =params[:start_date] - session[:end_date]=params[:end_date] - end - if(params[:project_id].nil? != true ) - if(params[:project_id].empty?) - session[:project_id]=nil - else - session[:project_id] =params[:project_id] - end - end + before_action :authenticate_user, :except=>[:index] - query_hash = {} - query_hash.merge!(user_id: current_user.id) - if(session[:start_date] != nil) - query_hash.merge!(log_date: session[:start_date]..session[:end_date]) - else - query_hash.merge!(log_date: 1.week.ago..Date.today) - end - @user_log_summary=@daily_log.user_create_summary(query_hash,session[:project_id]) - + def new + @daily_log = current_user.daily_logs.new + @projects = Project.where("name !='"+Project::LEARNING+"'") + @user_log_summary = DailyLog.create_user_summary(params,current_user.id, params[:project_id],log_date:nil) end def create - ActiveRecord::Base.transaction do - daily_log=DailyLog.new.create_log(current_user.id,params[:takeaway],params[:datetime_ida]) - count = 0 - count2=1 - while count "daily_logs/user_summary",object: @log_summary,locals: { log_summary: @log_summary} + @log_summary = DailyLog.create_user_summary(nil,nil,nil, params[:log_date]) + render :partial => "daily_logs/user_summary",locals: { log_summary: @log_summary} end + def user_logs - query_hash = {} - if(!params[:user_id].nil?) - query_hash.merge!(user_id: params[:user_id]) - else - query_hash.merge!(user_id: current_user.id) - end - if(!params[:start_date].nil?) - query_hash.merge!(log_date: params[:start_date]..params[:end_date]) - else - query_hash.merge!(log_date: 1.week.ago..Date.today) - end - if(params[:project_id].nil? or params[:project_id].empty?) - @user_logs=DailyLog.new.user_create_summary(query_hash,nil) - else - @user_logs=DailyLog.new.user_create_summary(query_hash,params[:project_id]) - end + @user_logs = DailyLog.create_user_summary(params,current_user.id,params[:project_id],nil) + render :partial => "daily_logs/user_summary",locals: { log_summary: @user_logs} + end - render :partial => "daily_logs/user_summary",object: @user_logs,locals: { log_summary: @user_logs} + def edit_log + @edit_log = DailyLog.find(params[:daily_log_id]).create_summary_record(nil) + @projects = Project.where("name !='"+Project::LEARNING+"'") + @daily_log_id = params[:daily_log_id] end + def update + begin + ActiveRecord::Base.transaction do + DailyLog.find(params[:daily_log_id]).update_daily_log_and_log_entries(params[:log_entries],params[:learning_log],params[:takeaway],params[:new_log_entries]) + end + flash[:info] = "Updated successfully" + redirect_to new_daily_log_path + rescue + flash[:info] = "Update failed,Please try again" + redirect_to new_daily_log_path + end + end end + diff --git a/app/helpers/daily_logs_helper.rb b/app/helpers/daily_logs_helper.rb index c648eb7..46962b1 100644 --- a/app/helpers/daily_logs_helper.rb +++ b/app/helpers/daily_logs_helper.rb @@ -1,3 +1,4 @@ module DailyLogsHelper + #TODO move this code to model search method + end -end \ No newline at end of file diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 71fbba5..2148120 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -2,4 +2,4 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true -end + end diff --git a/app/models/daily_log.rb b/app/models/daily_log.rb index 501c1a9..c06bc75 100644 --- a/app/models/daily_log.rb +++ b/app/models/daily_log.rb @@ -1,80 +1,101 @@ class DailyLog < ApplicationRecord - has_many :log_entries, :class_name => 'LogEntry',:dependent => :delete_all - belongs_to :user + has_many :log_entries, :class_name => 'LogEntry', :dependent => :delete_all + belongs_to :user + validates :user_id, presence: true include ApplicationHelper - def create_log (user_id,takeaway,log_date) - #TODO save daily logs and its log entries in a active record transaction - ActiveRecord::Base.transaction do - DailyLog.create(log_date: log_date,user_id: user_id,takeaway: takeaway ) - end - - end - def user_create_summary(query_hash,project_id) - if(!project_id.nil?) - daily_logs= DailyLog.where(query_hash).joins(:log_entries).where("log_entries.project_id=#{project_id}") + + # DailyLog.create_user_summary - making sense + + def self.create_user_summary(params,user_id, project_id, log_date) + query_hash = {} + query_hash = DailyLog.build_query_hash(params,user_id) if params.present? + if( project_id.present? ) + daily_logs = DailyLog.where(query_hash).joins(:log_entries).where(log_entries: {project_id: project_id}).order("log_date DESC").distinct + elsif(!query_hash.present? and project_id.nil? and log_date.present? ) + daily_logs = DailyLog.where(log_date: log_date).order("log_date DESC") else - daily_logs=DailyLog.where(query_hash) + daily_logs = DailyLog.where(query_hash).order("log_date DESC") end - log_summary=Hash.new - daily_logs.each_with_index do |daily_log,index| - summary_record=daily_log.create_record() - log_summary[index]=summary_record + daily_log_summary = Hash.new + daily_logs.each_with_index do |daily_log,index| + daily_log_summary[index] = daily_log.create_summary_record(project_id) end + daily_log_summary + end + + # @daily_log.create_summary_record_hash + # + # TODO: Rename to create_summary_record_hash + def create_summary_record(project_id) + summary_record=Hash.new + summary_record[:name] = self.user.name + summary_record[:user_id] = self.user.id + summary_record[:picture] = self.user.picture + summary_record[:log_id] = self.id + summary_record[:takeaway] = self.takeaway.to_s + summary_record[:learning]= self.log_entries.where(project_id:Project.where(client_name: Project::LEARNING).first.id).first.log_text + summary_record[:clients] = self.clients_project_log_record(project_id) + summary_record[:logdate] = self.log_date.strftime('%v') + summary_record - log_summary +=begin + summary_record = { + :name => self.user.name, + :user_id => ... + } +=end end - def create_summary(log_date:) - daily_logs= DailyLog.where(log_date: log_date) - log_summary=Hash.new - daily_logs.each_with_index do |daily_log,index| - summary_record = daily_log.create_record() - log_summary[index]=summary_record + # @daily_log.clients_project_log_record_hash + def clients_project_log_record(project_id) + clients = Project.where.not(client_name: Project::LEARNING).distinct.pluck('client_name') + project_logs = Hash.new() + clients.each do |client| + if( project_id.present? ) + project_log_ids = self.log_entries.joins(:project).where(projects:{id: project_id, client_name:"#{client}" }).pluck(:id,:project_id) + else + project_log_ids = self.log_entries.joins(:project).where("projects.client_name='#{client}'").pluck(:id,:project_id) + end + project_log_logtext = Hash.new{|h,k| h[k] = []} + project_log_ids.each do |project_id_log_id| + project_log_logtext[Project.find(project_id_log_id[1]).name] << [LogEntry.find_by_id(project_id_log_id[0]).log_text,project_id_log_id[0]] + end + project_logs[client.to_s]=project_log_logtext end - log_summary + project_logs end - def create_record() - - summary_record=Hash.new - summary_record[:name] = User.where("id=#{self.user_id}")[0].name; - #summary_record[:name] = current_user.name - #summary_record[:name]=User.find(key.user_id)[0].name - summary_record[:takeaway]=self.takeaway.to_s - summary_record[:learning]= LogEntry.where(:daily_log_id => self.id).joins(:project).where("projects.client_name='Learning'")[0].log_text; - summary_record[:beautifulcode]=self.company_record() - summary_record[:clients] =self.client_record() - summary_record[:logdate]=self.log_date - summary_record - end - def company_record() - company_record={} - #TODO move where clauses to models instance methods - #if(project_id != nil) - #log_ids=LogEntry.where(:daily_log_id => self.id,:project_id => project_id).joins(:project).where("projects.client_name='BeautifulCode'").pluck(:id) - #else - log_ids=LogEntry.where(:daily_log_id => self.id).joins(:project).where("projects.client_name='BeautifulCode'").pluck(:id) - #end - log_ids.each do |log_id| - company_record[LogEntry.find_by_id(log_id).project.name.to_s]=LogEntry.find_by_id(log_id).log_text.to_s; + # TODO: Move transaction to this method and dont use it in the controller. + def update_daily_log_and_log_entries(log_entry_records,learning,takeaway,new_log_entries) + log_entry_records.each do |project_id,log_entries| + log_entries.each do |log_entry_id,log_text| + self.log_entries.find(log_entry_id).update_attributes(project_id: project_id, log_text:log_text); end - company_record - end - def client_record() - clients=Project.where.not(client_name: ['BeautifulCode', 'Learning']).pluck('distinct client_name') - project_logs=Hash.new(); - clients.each do |client| - #if(project_id !=nil) - #project_log_ids=LogEntry.where(:daily_log_id => self.id,:project_id => project_id).joins(:project).where("projects.client_name='#{client}'").pluck(:id,:project_id) - #else - project_log_ids=LogEntry.where(:daily_log_id => self.id).joins(:project).where("projects.client_name='#{client}'").pluck(:id,:project_id) - # end - project_log_logtext=Hash.new() - project_log_ids.each do |log_id,pid| - project_log_logtext[Project.find_by_id(pid).name]=LogEntry.find_by_id(log_id).log_text; + end + self.update_attributes(:takeaway => takeaway) + learning_project_id = Project.where(name: Project::LEARNING).pluck(:id).first.to_i + self.log_entries.find_by_project_id(learning_project_id).update_attributes(log_text: learning) + if(new_log_entries.present?) + new_log_entries.each do |project_id,log_entries| + log_entries.each do|logtext| + self.log_entries.create(project_id:project_id,log_text:logtext) end - project_logs[client.to_s]=project_log_logtext; end - project_logs -end + end + end + + def self.build_query_hash(params, current_user_id) + query_hash ={} + query_hash[:user_id] = params[:user_id] || current_user_id + if(params[:start_date].present?) + query_hash.merge!(log_date: params[:start_date]..params[:end_date]) + else + query_hash.merge!(log_date: 1.week.ago.strftime('%v')..Date.today.strftime('%v')) + end + query_hash + end + + def self.check_log_entry_exists(user_id,log_date) + DailyLog.where(user_id: user_id, log_date:log_date).count==0 ? true : false + end end diff --git a/app/models/log_entry.rb b/app/models/log_entry.rb index 9cc9285..c1e3834 100644 --- a/app/models/log_entry.rb +++ b/app/models/log_entry.rb @@ -3,6 +3,7 @@ class LogEntry < ApplicationRecord belongs_to :project #def create_logentry(project_id,logtext,daily_log_id) + ##TODO wheh you are not using a method remove it def create_logentry(project_id,logtext) LogEntry.create(project_id: project_id,log_text: logtext,daily_log_id: daily_log_id) end diff --git a/app/models/project.rb b/app/models/project.rb index b379b2d..642f521 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,9 +1,8 @@ class Project < ApplicationRecord - #attr_accessible :name, :client has_and_belongs_to_many :users has_many :log_entries , :class_name => 'LogEntry' accepts_nested_attributes_for :log_entries - + BEAUTIFUL_CODE_CLIENT = "BeautifulCode" SOJERN_CLIENT = "Sojern" LEARNING = "Learning" diff --git a/app/models/user.rb b/app/models/user.rb index f9a5714..a9b0c6d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,6 +1,9 @@ class User < ActiveRecord::Base has_and_belongs_to_many :projects has_many :daily_logs + # TODO: write in the same line + validates :name, presence: true + validates :email, presence: true def self.from_omniauth(auth) where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user| diff --git a/app/views/daily_logs/_log_entry_fields.html.haml b/app/views/daily_logs/_log_entry_fields.html.haml deleted file mode 100644 index 2e9a42b..0000000 --- a/app/views/daily_logs/_log_entry_fields.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -.nested-fields - .field - = f.label :description - %br - = f.text_field :log_text - = link_to_remove_association "remove task", f \ No newline at end of file diff --git a/app/views/daily_logs/_user_list.html.haml b/app/views/daily_logs/_user_list.html.haml index cbba10c..0f2728e 100644 --- a/app/views/daily_logs/_user_list.html.haml +++ b/app/views/daily_logs/_user_list.html.haml @@ -1,5 +1,5 @@ .container - - @All_users.each_slice(4).each do |users| + - @all_users.each_slice(4).each do |users| .row - users.each do |user| .col-sm-3.col-xs-6.hover-cover @@ -10,4 +10,4 @@ =user[:name] %br :javascript - DailyLog(); \ No newline at end of file + DailyLog(); diff --git a/app/views/daily_logs/_user_summary.html.haml b/app/views/daily_logs/_user_summary.html.haml index 5c7eab7..2d4ce9d 100644 --- a/app/views/daily_logs/_user_summary.html.haml +++ b/app/views/daily_logs/_user_summary.html.haml @@ -2,35 +2,45 @@ %div.row %div.col-md-8.page .row - .col-md-4 + .col-md-1 + = image_tag (image_url(value[:picture] )), class:"imagecircle" + .col-md-3 %h2 =value[:name] - .col-md-8.pull-right + .col-md-8.pull-right.datecolor =value[:logdate] %h3 Work - -value[:beautifulcode].each do |project,logtext| - %div - =project - %p - =logtext + -if value[:beautifulcode].present? + -value[:beautifulcode].each do |project,logtexts| + %a.ui.tag.label + =project + %ul + -logtexts.each do |logtext| + %li + =logtext[0] -value[:clients].each do |client,records| - %h5 - =client - -records.each do |pname,log| - %div + -records.each do |pname,logs| + %a.ui.tag.label =pname - %p - =log + %ul + -logs.each do|log| + %li + =log[0] + %hr %h5 Learning %p =value[:learning] + %hr %h5 TakeAway - %p + %div{display:"list-item"} =value[:takeaway] + -if(current_user.id == value[:user_id]) + %div + =link_to "Edit log",edit_log_path(:daily_log_id => value[:log_id]),:class => "btn btn-change btn-md pull-right" + %br %br %br - %br \ No newline at end of file diff --git a/app/views/daily_logs/edit_log.html.haml b/app/views/daily_logs/edit_log.html.haml new file mode 100644 index 0000000..edeee7d --- /dev/null +++ b/app/views/daily_logs/edit_log.html.haml @@ -0,0 +1,68 @@ +%div.user_summary + %div.row + %div.col-md-8.page + =form_tag update_path, :method => :post do + .row + .col-md-1 + = image_tag (image_url(@edit_log[:picture] )), class:"imagecircle" + .col-md-4 + %h2 + =@edit_log[:name] + .col-md-7.pull-right.datecolor + =@edit_log[:logdate] + %h3.headerclass + Work + -if @edit_log[:beautifulcode].present? + -@edit_log[:beautifulcode].each do |project,logtexts| + %div + %div + =select_tag "projects[]", options_for_select(@projects.map {|u| [u.name,u.id]}),:onchange => "alert_me_test()",:include_blank => "#{project}", :value => @projects.where(:name =>"#{project}").pluck(:id).first.to_s,:class => "added" + %h5.task + Task + %div + %div + -logtexts.each do |logtext| + =text_field_tag("log_entries["+@projects.where(:name =>"#{project}").pluck(:id).first.to_s+"]["+logtext[1].to_s+"]","#{logtext[0]}",:class => "form-control existing") + %br + %button.btn.btn-default.add_field_button + Add Task + %br + %div.project + -@edit_log[:clients].each do |client,records| + -records.each do |project,logtexts| + %div + %div + =select_tag "projects[]", options_for_select(@projects.map {|u| [u.name,u.id]}),:onchange => "alert_me_test()",:include_blank => "#{project}", :value => @projects.where(:name =>"#{project}").pluck(:id).first.to_s,:class => "added" + %h5.task + Task + %div + %div + -logtexts.each do |logtext| + =text_field_tag("log_entries["+@projects.where(:name =>"#{project}").pluck(:id).first.to_s+"]["+logtext[1].to_s+"]","#{logtext[0]}",:class => "form-control existing") + %br + %button.btn.btn-default.add_field_button{"id"=>"company"} + Add Task + %hr + %button.btn.btn-default.add_project_button + Add Project + %br + + %h5 + Learning + %p + =text_field_tag("learning_log","#{@edit_log[:learning]}",:class => "form-control") + %h5 + TakeAway + %p + =text_field_tag("takeaway","#{@edit_log[:takeaway]}",class: "form-control") + %input{"type" => "hidden","value" => "#{@daily_log_id}","name" => "daily_log_id"} + %hr + = submit_tag("Submit", class: "btn btn-change btn-md btn-md pull-right" ) + + %br + %br + %br + + +:javascript + EditLog(); diff --git a/app/views/daily_logs/index.html.haml b/app/views/daily_logs/index.html.haml index f816517..fc03f32 100644 --- a/app/views/daily_logs/index.html.haml +++ b/app/views/daily_logs/index.html.haml @@ -1,5 +1,5 @@ +-##TODO you are going to change this UX %pre - Find me at `app/views/home/index.html.haml` - if current_user = link_to 'fill the daily log', new_daily_log_path, class: 'btn btn-primary btn-lg' - else diff --git a/app/views/daily_logs/new.html.haml b/app/views/daily_logs/new.html.haml index cd775c0..024d602 100644 --- a/app/views/daily_logs/new.html.haml +++ b/app/views/daily_logs/new.html.haml @@ -1,43 +1,50 @@ %div.container-fluid %div.row %div.col-md-4 - %input{ "type"=>"text","name"=>"daterange"} + #calendar2.ui + .ui.input.left.icon + %i.calendar.icon + %input{ "type"=>"text","name"=>"daterange"} %div.row %div.col-md-4 - = select_tag "projects_filter", options_for_select(@projects.map {|u| [u.name,u.id]}),{:include_blank => "All", :default => nil} + = select_tag "projects_filter", options_for_select(@projects.map {|u| [u.name,u.id]}),{:include_blank => "All", :default => nil,:class => "projects_filter"} +-#if(!@user_log_summary.empty? && (@user_log_summary[0][:logdate] !=Date.today().strftime("%v")) + -#move this code to partial %div.row %div.col-md-8.page = form_tag daily_logs_path, :method => :post do .row + .col-md-1 + = image_tag (image_url(current_user.picture )), class:"imagecircle" .col-md-4 - %h2 + %h4.centeralign =current_user.name - .col-md-8.pull-right + .col-md-7.pull-right =date_field_tag(:datetime_ida, Date.today) - %h3 + %h3.headerclass Work %div.project - = select_tag "projects[]", options_for_select(@projects.map {|u| [u.name,u.id]}),:onchange => "alert_me_test()" - %div.task - %br - %h3 - Task - %input.form-control{"maxlength"=>"300","name"=>"projects[]LogText[]","required"=>"required","type"=>"text","placeholder" =>" enter LogEntry"} - %br + = select_tag "projects[]", options_for_select(@projects.map {|u| [u.name,u.id]}),:class => "added",:prompt => "Select Project", :required => "required" + %br + %h5.task + Task %div + %input.form-control{"maxlength"=>"300","required"=>"required","type"=>"text","placeholder" =>" enter LogEntry"} + %div + %br %button.btn.btn-default.add_field_button{"id"=>"company"} - add more - %hr + Add Task + %hr %div %button.btn.btn-default.add_project_button{} - add project + Add Project %hr %div %h3 Learning %p what did you learn today? - %input.form-control{"name"=>"LearningLog","required"=>"required","type"=>"text","placeholder" =>" enter learning log "} + %input.form-control{"name"=>"log_entry[4][]","required"=>"required","type"=>"text","placeholder" =>" enter learning log "} %hr %div %h3 @@ -46,15 +53,19 @@ what are your takeaways? %input.form-control{"name"=>"takeaway","required"=>"required","type"=>"text","placeholder" =>" takeaways for the day "} %hr - = submit_tag("Submit", class: "btn btn-success btn-md btn-md pull-right" ) + = submit_tag("Submit", class: "btn btn-change btn-md btn-md pull-right" ) %br %br %br .user_summary - =render :partial => "daily_logs/user_summary",object: @user_log_summary,locals: { log_summary: @user_log_summary} + - if @user_log_summary + -##TODO why are sending @user_log_summary twice + =render :partial => "daily_logs/user_summary",object: @user_log_summary,locals: { log_summary: @user_log_summary} :javascript DailyLog(); + $(document).ready(function() { + }); diff --git a/app/views/daily_logs/people_logs.js b/app/views/daily_logs/people_logs.js deleted file mode 100644 index cdc8c3f..0000000 --- a/app/views/daily_logs/people_logs.js +++ /dev/null @@ -1 +0,0 @@ -window.location.reload(); \ No newline at end of file diff --git a/app/views/daily_logs/summary.html.haml b/app/views/daily_logs/summary.html.haml index 6acf820..caf2f16 100644 --- a/app/views/daily_logs/summary.html.haml +++ b/app/views/daily_logs/summary.html.haml @@ -1,3 +1,4 @@ +-#TODO remove deprecated files %h1 Summary =render :partial => "daily_logs/user_summary",object: @log_summary,locals: { log_summary: @log_summary} diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index a20148d..5d04f01 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -30,50 +30,30 @@ %script(src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js") %body - / Fixed navbar - / %nav.navbar.navbar-toggleable-md.navbar-inverse.fixed-top.bg-inverse - / %button.navbar-toggler.navbar-toggler-right{"aria-controls" => "navbarCollapse", "aria-expanded" => "false", "aria-label" => "Toggle navigation", "data-target" => "#navbarCollapse", "data-toggle" => "collapse", :type => "button"} - / %span.navbar-toggler-icon - / %a.navbar-brand{:href => "#"} DailyRecap - / #navbarCollapse.collapse.navbar-collapse - / %ul.navbar-nav.mr-auto - / %li.nav-item.active - / %a.nav-link{:href => "#"} - / Home - / %span.sr-only (current) - / %li.nav-item - / %a.nav-link{:href => "#"} Link - / %li.nav-item - / - if current_user - / = link_to 'Logout', signout_path, :class => "nav-link" - / - else - / = link_to 'Login', "/auth/google_oauth2", :class => "nav-link" - / %li.nav-item - / %a.nav-link.disabled{:href => "#"} Disabled - / %form.form-inline.mt-2.mt-md-0 - / %input.form-control.mr-sm-2{:placeholder => "Search", :type => "text"}/ - / %button.btn.btn-outline-success.my-2.my-sm-0{:type => "submit"} Search - / Begin page content - /.container %div.toggled{:id=>"wrapper"} %div{:id=>"sidebar-wrapper"} %ul.sidebar-nav %li.sidebar-brand %a{:href=>"#"} - Daily recap - + Daily Recap %li %a.active{:href=> new_daily_log_path} My Logs %li - %a{:href=> people_logs_path}> + %a{:href=> people_logs_path} People Logs %li - if current_user - = link_to 'Logout', signout_path, :class => "nav-link" + %a{:href => signout_path } + Logout - else - = link_to 'Login', "/auth/google_oauth2", :class => "nav-link" + %a{:href => "/auth/google_oauth2"} + Login + #container.container + - flash.each do |message_type, message| + .alert{ class: "alert-#{message_type}" } + = message %div{:id=>"page-content-wrapper"} = yield diff --git a/config/projects.yml b/config/projects.yml new file mode 100644 index 0000000..d1a21ff --- /dev/null +++ b/config/projects.yml @@ -0,0 +1,13 @@ +projects: + - name: internal_apps + client_name: BeautifulCode + - name: RevDirect + client_name: Sojern + - name: Debtinator + client_name: Sojern + - name: Learning + client_name: Learning + - name: Navigator + client_name: Sojern + + diff --git a/config/routes.rb b/config/routes.rb index c3872be..687a995 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true Rails.application.routes.draw do - get 'auth/:provider/callback', to: 'sessions#create' + get 'auth/:provider/callback', to: 'sessions#create' get 'auth/failure', to: redirect('/') get 'signout', to: 'sessions#destroy', as: 'signout' get '/summary', :to => 'daily_logs#summary', as: 'summary' @@ -10,13 +10,12 @@ post 'daily_logs/refresh', :to => 'daily_logs#refresh' get 'daily_logs/user_list', :to => 'daily_logs#user_list' match 'daily_logs/user_logs', :to => 'daily_logs#user_logs', via:[:GET,:POST] + match 'daily_logs/edit_log', :to => 'daily_logs#edit_log', via:[:GET,:POST],as:'edit_log' + match 'daily_logs/update', :to =>'daily_logs#update',via: [:POST], as:'update' resources :sessions, only: [:create, :destroy] resources :daily_logs, only: [:new, :create] - # resources :daily_logs do - # get "/daily_logs/new", on: :collection - # end resources :projects - + root :to => 'daily_logs#index' end diff --git a/db/seeds.rb b/db/seeds.rb index 1beea2a..61ca0cd 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,7 +1,8 @@ -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). -# -# Examples: -# -# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) -# Character.create(name: 'Luke', movie: movies.first) +data = YAML.load_file 'config/projects.yml' +data['projects'].each do |project| + #TODO refactor this + #name = project["name"] + #client_name = project["client_name"] + #Project.create!(name: name, client_name: client_name) + Project.create!(name: project["name"], client_name: project["client_name"]) +end diff --git a/spec/factories.rb b/spec/factories.rb index 3ad0175..e93141b 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,27 +1,27 @@ FactoryGirl.define do factory :user do name "John" - uid "3" + uid "1" email "abhipatnala@gmail.com" provider "google" end factory :daily_log do - log_date = '2017-05-31' - takeaway ="spend more time on learning" - user_id ="1" + log_date Date.today + takeaway 'spend more time on learning' + user_id '1' end factory :log_entry do - log_text ="done with views" - project_id ="2" - daily_log_id ="1" + log_text "done with views" + project_id "2" end factory :project do - name ="revdirect" - client_name ="Sojern" + name "macnator" + client_name "Sojern" end factory :feedback do - feedback_text="good job" - user_id="2" - daily_log_id="2" + feedback_text "good job" + user_id "2" + daily_log_id "2" end -end + end + diff --git a/spec/models/daily_log_spec.rb b/spec/models/daily_log_spec.rb deleted file mode 100644 index a61164a..0000000 --- a/spec/models/daily_log_spec.rb +++ /dev/null @@ -1,32 +0,0 @@ -require 'rails_helper' -RSpec.describe DailyLog, type: :model do - let(:daily_log) { FactoryGirl.build(:daily_log) } - [:log_date, :takeaway].each do |msg| - it "should respond to #{msg}" do - expect(daily_log).to respond_to(msg) - end - end - - it 'should belong to a user' - - it 'should have many log_entries' - - - - # describe :record_create do - # before do - # daily_log.user_id = user.id - # daily_log.save - # allow(daily_log).to receive(:company_record).and_return nil - # allow(daily_log).to receive(:client_record).and_return nil - # end - # it 'should return formatted daily log record' do - # record = daily_log.record_create - # #expect(record.keys).to match_array([:name, :takeaway, :learning, :beautifulcode, :clients]) - # #expect(record.keys).to match_array([:name]) - # end - # end -end - - - diff --git a/spec/models/dailylog_spec.rb b/spec/models/dailylog_spec.rb index 2a3ad61..2a3ddb2 100644 --- a/spec/models/dailylog_spec.rb +++ b/spec/models/dailylog_spec.rb @@ -1,39 +1,204 @@ require 'rails_helper' RSpec.describe DailyLog, type: :model do - #pending "add some examples to (or delete) #{__FILE__}" + let(:user) {User.create(name:"avinash",email:"avinash@beautifulcode.in") } let(:daily_log) { FactoryGirl.build(:daily_log) } - [:log_date, :takeaway].each do |msg| + let(:log_entry) { FactoryGirl.build(:log_entry) } + let(:project) { FactoryGirl.create(:project) } + let(:learning_project) { Project.create(name: "Learning", client_name: "Learning") } + let(:learning) { LogEntry.new } + let(:revdirect) { Project.create(name:"revdirect", client_name:"Sojern") } + let(:revdirect_log_entry) { LogEntry.new } + before do + Project.delete_all + LogEntry.delete_all + daily_log.user_id=user.id + daily_log.save + log_entry.daily_log_id=daily_log.id + log_entry.project_id=project.id + log_entry.save + learning.update_attributes(daily_log_id: daily_log.id,project_id: learning_project.id,log_text: "advanced jquery") + learning.save + revdirect_log_entry.update_attributes(log_text:"Solved ticket 3", project_id: revdirect.id , daily_log_id: daily_log.id) + revdirect_log_entry.save + end + + [:log_date, :takeaway].each do |msg| it "should respond to #{msg}" do expect(daily_log).to respond_to(msg) end end it "should have many log_entries" do - t = DailyLog.reflect_on_association(:log_entries) - t.macro.should == :has_many + association = DailyLog.reflect_on_association(:log_entries) + + expect(association.macro).to eq(:has_many) end + it 'should belong to a user' do - t = DailyLog.reflect_on_association(:user) - t.macro.should == :belongs_to - end - # describe :create_record do - # log=DailyLog.new - # before do - # log.id=1111 - # log.user_id = 1 - # log.log_date=Date.today - # log.takeaway="need to improve" - # log.save - # allow(log.class).to receive(:company_record).and_return nil - # allow(log.class).to receive(:client_record).and_return nil - # end - # it 'should return formatted daily log record' do - # #:log_date = Date.today - # record = log.create_summary - # expect(record.keys).to match_array([:name, :takeaway, :learning, :beautifulcode, :clients]) - # expect(record.keys).to match_array([:name]) - # end - # end + association = DailyLog.reflect_on_association(:user) + + expect(association.macro).to eq(:belongs_to) + end + + it 'should have one or none dailylog entry for given date for given user' do + @dailylog = DailyLog.where(log_date: Date.today,user_id: 1) + + expect(@dailylog.count).to be <= 1 + end + + it 'should delete all associated log entries on deleting daily log' do + count =daily_log.log_entries.count + total_count =LogEntry.all.count + daily_log.destroy + + expect(LogEntry.all.count).to eq(total_count-count) + end + + describe 'validations' do + it 'should have valid user_id' do + daily_log.update_attributes(user_id: nil) + + expect(daily_log.errors).to include(:user_id) + end + end + + describe :create_user_summary do + context "when project id is nil" do + it "should return daily logs for all projects" do + params= { user_id: user.id } + records = daily_log.class.create_user_summary(params,nil,nil,nil) + + expect(records.values.first[:clients].values.first.keys).to match_array(["macnator","revdirect"]) + end + end + context "when project id is not nil" do + it "should return daily_logs for specific project" do + params ={user_id: user.id} + records= daily_log.class.create_user_summary(params,nil,revdirect.id,nil) + + expect(records.values.first[:clients].values.first.keys).to match_array(["revdirect"]) + end + end + context "when project_id and query_hash are not present and log date is present" do + it "should return daily logs of all users for that particular date" do + records= daily_log.class.create_user_summary(nil,nil,nil,Date.today) + + expect(records.values.first[:logdate]).to eq(Date.today.strftime('%v')) + end + end + end + + describe :create_summary_record do + before do + allow(daily_log).to receive(:clients_project_log_record).and_return nil + end + it 'should return formatted daily log record' do + record = daily_log.create_summary_record(nil) + + expect(record.keys).to match_array([:name, :takeaway, :learning,:clients,:log_id,:logdate,:picture,:user_id]) + end + end + + describe :clients_project_log_record do + context "when project filter not applied" do + it "should return all project log entries" do + record = daily_log.clients_project_log_record(nil) + expect(record.values.first.keys).to match_array(["macnator","revdirect"]) + end + end + context "when project filter applied" do + it "should return project specific log entries" do + record =daily_log.clients_project_log_record(revdirect.id) + expect(record.values.first.keys).to match_array(["revdirect"]) + end + end + it "should not return learning log entries" do + record = daily_log.clients_project_log_record(nil) + project_record = daily_log.clients_project_log_record(revdirect.id) + + expect(record.values.first.keys).to match_array(["macnator","revdirect"]) + expect(project_record.values.first.keys).to match_array(["revdirect"]) + + end + end + + describe :update_daily_log_and_log_entries do + context "when new log entries added for dailylog" do + it "should add those logentries to database" do + log_entries = {revdirect.id => {revdirect_log_entry.id => "edited"}} + new_log_entries = { revdirect.id =>["new_record"] } + takeaway = "checing_updation" + learning = "checking_updation" + before_count = daily_log.log_entries.count + daily_log.update_daily_log_and_log_entries(log_entries,learning,takeaway,new_log_entries) + after_count =daily_log.log_entries.count + + expect(after_count).to eq(before_count+1) + + end + end + context "when existing records are modified" do + it "should update those logentries in database" do + log_entries = {revdirect.id => {revdirect_log_entry.id => "edited"}} + takeaway = "checking_updation" + learning = "checking_updation" + daily_log.update_daily_log_and_log_entries(log_entries,learning,takeaway,nil) + + expect(daily_log.log_entries.find(revdirect_log_entry.id).log_text).to eq("edited") + expect(daily_log.takeaway).to eq("checking_updation") + end + end + context "when no new log_entries are added for daily_log" do + it "should not add any log entries in database for that daily_log" do + log_entries = {revdirect.id => {revdirect_log_entry.id => "edited"}} + takeaway = "checking_updation" + learning = "checking_updation" + before_count =daily_log.log_entries.count + daily_log.update_daily_log_and_log_entries(log_entries,learning,takeaway,nil) + updated_count = daily_log.log_entries.count + + expect(updated_count).to eq(before_count) + end + end + end + + + describe :build_query_hash do + context "when date filter applied" do + it "should return valid hash" do + params = { user_id: 1, start_date: '25-07-2017',end_date: '30-07-2017' } + query_hash = daily_log.class.build_query_hash(params,nil) + + expect(query_hash.keys).to match_array([:user_id,:log_date]) + expect(query_hash.values[1]).to eq("25-07-2017".."30-07-2017") + end + end + context "when date filter not applied" do + it "should return valid hash" do + params={ user_id: 1 } + query_hash= daily_log.class.build_query_hash(params,nil) + value= 1.week.ago.strftime('%v')..Date.today.strftime('%v') + + expect(query_hash.keys).to match_array([:user_id,:log_date]) + expect(query_hash.values[1]).to eq(value) + end + end + end + + describe :check_log_entry_exists do + context "when log entry for the day exists" do + it "should return false " do + flag = daily_log.class.check_log_entry_exists(user.id, Date.today) + expect(flag).to eq(false) + end + end + context "when log entry for the day does not exists" do + it "should return true" do + flag = daily_log.class.check_log_entry_exists(user.id, Date.yesterday) + expect(flag).to eq(true) + end + end + end end diff --git a/spec/models/feedback_spec.rb b/spec/models/feedback_spec.rb index b7bc18f..410215d 100644 --- a/spec/models/feedback_spec.rb +++ b/spec/models/feedback_spec.rb @@ -1,21 +1,18 @@ require 'rails_helper' RSpec.describe Feedback, type: :model do - let(:feedbackentry) { FactoryGirl.build(:feedback) } - [:feedback_text, :user_id,:daily_log_id].each do |msg| + let(:feedback_entry) { FactoryGirl.build(:feedback) } + [:feedback_text, :user_id,:daily_log_id].each do |msg| it "should respond to #{msg}" do - expect(feedbackentry).to respond_to(msg) + expect(feedback_entry).to respond_to(msg) end end -<<<<<<< HEAD it "should belongs to user" do - t = Feedback.reflect_on_association(:user) - t.macro.should == :belongs_to + association = Feedback.reflect_on_association(:user) + association.macro.should == :belongs_to end it "should belongs to daily_log" do - t = Feedback.reflect_on_association(:daily_log) - t.macro.should == :belongs_to + association = Feedback.reflect_on_association(:daily_log) + association.macro.should == :belongs_to end -======= ->>>>>>> 3b127cb9e81258aac7731555728298c01f41f6d8 end diff --git a/spec/models/logentry_spec.rb b/spec/models/logentry_spec.rb index 84f65d1..45e1782 100644 --- a/spec/models/logentry_spec.rb +++ b/spec/models/logentry_spec.rb @@ -1,22 +1,23 @@ require 'rails_helper' RSpec.describe LogEntry, type: :model do - let(:entry) { FactoryGirl.build(:log_entry) } - [:log_text, :project_id,:daily_log_id].each do |msg| + let(:entry) { FactoryGirl.build(:log_entry) } + [:log_text, :project_id,:daily_log_id].each do |msg| it "should respond to #{msg}" do expect(entry).to respond_to(msg) end end -<<<<<<< HEAD - it "should belongs to daily_log" do - t = LogEntry.reflect_on_association(:daily_log) - t.macro.should == :belongs_to + + it "should belong to daily_log" do + association = LogEntry.reflect_on_association(:daily_log) + expect(association.macro).to eq(:belongs_to) end - it "should belongs to project" do - t = LogEntry.reflect_on_association(:project) - t.macro.should == :belongs_to + it "should belong to project" do + association = LogEntry.reflect_on_association(:project) + expect(association.macro).to eq(:belongs_to) end + it "should have valid log_text" do -======= ->>>>>>> 3b127cb9e81258aac7731555728298c01f41f6d8 + expect(entry.log_text.to_s.length).to be > 0 + end end diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index a061d0d..c433bc4 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1,51 +1,30 @@ require 'rails_helper' RSpec.describe Project, type: :model do -<<<<<<< HEAD - let(:project) { FactoryGirl.build(:Project) } - let(:id) { '111111' } - [:name, :client_name].each do |msg| -======= - let(:project) { FactoryGirl.build(:project) } - + let(:project) { FactoryGirl.create(:project) } [:name, :client_name].each do |msg| ->>>>>>> 3b127cb9e81258aac7731555728298c01f41f6d8 it "should respond to #{msg}" do expect(project).to respond_to(msg) end end -<<<<<<< HEAD + it "should have many users " do - t = Project.reflect_on_association(:users) - t.macro.should == :has_and_belongs_to_many + association = Project.reflect_on_association(:users) + association.macro.should == :has_and_belongs_to_many end it "should have many log_entries" do - t = Project.reflect_on_association(:log_entries) - t.macro.should == :has_many - end - context 'when newly created' do - it 'should not have any log entries' do - LogEntry.joins(:project).where("projects.id=1111").count.should == 0 - end - it 'should not have any users' do - User.joins(:project).where("projects.id=1111").count.should == 0 - - end + association = Project.reflect_on_association(:log_entries) + association.macro.should == :has_many end - - #it 'should not have any users' + context 'when newly created' do + it 'should not have any log entries' do + count = project.log_entries.count + expect(count).to eq(0) + end end -======= - it 'should have many users' +end - it 'should have many log entries' - context 'when newly created' do - it 'should not have any log entries' - it 'should not have any users' - end -end ->>>>>>> 3b127cb9e81258aac7731555728298c01f41f6d8 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 4463a63..2dbb6fb 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1,83 +1,54 @@ require 'rails_helper' RSpec.describe User, type: :model do - - describe :from_omniauth do -<<<<<<< HEAD -======= - ->>>>>>> 3b127cb9e81258aac7731555728298c01f41f6d8 + let(:user) { User.create(name: 'test', email: 'test@beautifulcode.in') } + describe :from_omniauth do it 'should get user details from oauth after successful authentication' do - OmniAuth.config.mock_auth[:google_oauth2] = OmniAuth::AuthHash.new({ - provider: 'google_oauth2', - uid: '123', - info: { - name: 'dummy', - email: 'dummy@dummy.com' - }, - credentials: { - token: 'dummy', - expires_at: 123456 - } - }) -<<<<<<< HEAD - -======= + OmniAuth.config.mock_auth[:google_oauth2] = OmniAuth::AuthHash.new({ + provider: 'google_oauth2', + uid: '123', + info: { + name: 'dummy', + email: 'dummy@dummy.com' + }, + credentials: { + token: 'dummy', + expires_at: 123456 + } + }) before_user_count = User.count - ->>>>>>> 3b127cb9e81258aac7731555728298c01f41f6d8 user = User.from_omniauth(OmniAuth.config.mock_auth[:google_oauth2]) expect(user.provider).to eq('google_oauth2') - expect(user.uid).to eq('123') - expect(user.name).to eq('dummy') - expect(user.email).to eq('dummy@dummy.com') - expect(user.oauth_token).to eq('dummy') - #expect(user.token_expires_at).to eq(123_456) -<<<<<<< HEAD - end - end - it "should have many daily_logs" do - t = User.reflect_on_association(:daily_logs) - t.macro.should == :has_many - end - it "should have many and belongs to projects" do - t = User.reflect_on_association(:projects) - t.macro.should == :has_and_belongs_to_many + expect(user.uid).to eq('123') + expect(user.name).to eq('dummy') + expect(user.email).to eq('dummy@dummy.com') + expect(user.oauth_token).to eq('dummy') + end end - context 'when newly created' do - it 'should return an empty collection for projects' do - User.joins(:project).where('id=?',user.id).count.should == 0 - - it 'should return an empty collection for daily_logs' do - User.joins(:daily_logs).where('id=?',user.id).count.should == 0 - + it "should have many daily_logs" do + association = User.reflect_on_association(:daily_logs) + association.macro.should == :has_many end -======= - - expect(User.count).to eq(before_user_count+1) - end - - pending 'should not create a new user if the user already exists' - - context 'when authentication fails' do - # describe what happens when authentication fails. + it "should have many and belongs to projects" do + association = User.reflect_on_association(:projects) + association.macro.should == :has_and_belongs_to_many + end + describe 'validations' do + it 'should have valid name' do + user.update_attributes(name: nil) + expect(user.errors).to include(:name) end - end - - it 'should have many projects' + it 'should have valid email' do + user.update_attributes(email: nil) + expect(user.errors).to include(:email) + end + end +end - it 'should have many daily_logs' - context 'when newly created' do - it 'should return an empty collection for projects' - it 'should return an empty collection for daily_logs' - end - #pending "add some examples to (or delete) #{__FILE__}" ->>>>>>> 3b127cb9e81258aac7731555728298c01f41f6d8 -end