diff options
28 files changed, 333 insertions, 117 deletions
diff --git a/CHANGELOG b/CHANGELOG index 09b60e8e54a..22f38024f93 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,11 @@ Please view this file on the master branch, on stable branches it's out of date. v 7.10.0 (unreleased) + - enable line wrapping per default and remove the checkbox to toggle it (Hannes Rosenögger) + - extend the commit calendar to show the actual commits made on a date (Hannes Rosenögger) - Add a service to support external wikis (Hannes Rosenögger) + - List new commits for newly pushed branch in activity view. + - Add changelog, license and contribution guide links to project sidebar. v 7.9.0 (unreleased) - Add HipChat integration documentation (Stan Hu) @@ -39,7 +39,7 @@ gem "browser" # Extracting information from a git repository # Provide access to Gitlab::Git library -gem "gitlab_git", '~> 7.1.0' +gem "gitlab_git", '~> 7.1.2' # Ruby/Rack Git Smart-HTTP Server Handler gem 'gitlab-grack', '~> 2.0.0.rc2', require: 'grack' diff --git a/Gemfile.lock b/Gemfile.lock index e728115fa98..a454461ec26 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -213,7 +213,7 @@ GEM mime-types (~> 1.19) gitlab_emoji (0.1.0) gemojione (~> 2.0) - gitlab_git (7.1.1) + gitlab_git (7.1.2) activesupport (~> 4.0) charlock_holmes (~> 0.6) gitlab-linguist (~> 3.0) @@ -705,7 +705,7 @@ DEPENDENCIES gitlab-grack (~> 2.0.0.rc2) gitlab-linguist (~> 3.0.1) gitlab_emoji (~> 0.1) - gitlab_git (~> 7.1.0) + gitlab_git (~> 7.1.2) gitlab_meta (= 7.0) gitlab_omniauth-ldap (= 1.2.1) gollum-lib (~> 4.0.0) diff --git a/app/assets/javascripts/behaviors/toggle_diff_line_wrap_behavior.coffee b/app/assets/javascripts/behaviors/toggle_diff_line_wrap_behavior.coffee deleted file mode 100644 index 691ed4f98ae..00000000000 --- a/app/assets/javascripts/behaviors/toggle_diff_line_wrap_behavior.coffee +++ /dev/null @@ -1,14 +0,0 @@ -$ -> - # Toggle line wrapping in diff. - # - # %div.diff-file - # %input.js-toggle-diff-line-wrap - # %td.line_content - # - $("body").on "click", ".js-toggle-diff-line-wrap", (e) -> - diffFile = $(@).closest(".diff-file") - if $(@).is(":checked") - diffFile.addClass("diff-wrap-lines") - else - diffFile.removeClass("diff-wrap-lines") - diff --git a/app/assets/javascripts/calendar.js.coffee b/app/assets/javascripts/calendar.js.coffee index 19ea4ccc4cf..2891a48e249 100644 --- a/app/assets/javascripts/calendar.js.coffee +++ b/app/assets/javascripts/calendar.js.coffee @@ -4,7 +4,7 @@ class @calendar day: "numeric" year: "numeric" - constructor: (timestamps, starting_year, starting_month) -> + constructor: (timestamps, starting_year, starting_month, calendar_activities_path) -> cal = new CalHeatMap() cal.init itemName: ["commit"] @@ -26,5 +26,16 @@ class @calendar ] legendCellPadding: 3 onClick: (date, count) -> - return - return + formated_date = date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + $(".calendar_commit_activity").fadeOut 400 + $.ajax + url: calendar_activities_path + data: + date: formated_date + cache: false + dataType: "html" + success: (data) -> + $(".user-calendar-activities").html data + $(".calendar_commit_activity").find(".js-toggle-content").hide() + $(".calendar_commit_activity").fadeIn 400 + diff --git a/app/assets/stylesheets/generic/calendar.scss b/app/assets/stylesheets/generic/calendar.scss index 9483b26164e..e2ab7fc51a5 100644 --- a/app/assets/stylesheets/generic/calendar.scss +++ b/app/assets/stylesheets/generic/calendar.scss @@ -1,29 +1,45 @@ -.calendar_onclick_placeholder { - padding: 0 0 2px 0; -} - -.calendar_commit_activity { - padding: 5px 0 0; -} - -.calendar_onclick_second { - font-size: 14px; - display: block; -} - -.calendar_onclick_hr { - padding: 0; - margin: 10px 0; -} +.user-calendar-activities { + + .calendar_commit_activity { + padding: 5px 0 0; + } + + .calendar_onclick_hr { + padding: 0; + margin: 10px 0; + } + + .calendar_commit_date { + color: #999; + } + + .calendar_activity_summary { + font-size: 14px; + } -.calendar_commit_date { - color: #999; -} + .str-truncated { + max-width: 70%; + } -.calendar_activity_summary { - font-size: 14px; + .text-expander { + background: #eee; + color: #555; + padding: 0 5px; + cursor: pointer; + margin-left: 4px; + &:hover { + background-color: #ddd; + } + } + + .commit-row-message { + color: #333; + &:hover { + color: #444; + text-decoration: underline; + } + } } - /** * This overwrites the default values of the cal-heatmap gem */ diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8a13394dbac..68130eb128c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -32,6 +32,7 @@ class UsersController < ApplicationController def calendar projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids) + calendar = Gitlab::CommitsCalendar.new(projects, @user) @timestamps = calendar.timestamps @starting_year = calendar.starting_year @@ -40,6 +41,24 @@ class UsersController < ApplicationController render 'calendar', layout: false end + def calendar_activities + projects = Project.where(id: authorized_projects_ids & @user.contributed_projects_ids) + + date = Date.parse(params[:date]) rescue nil + if date + @calendar_activities = Gitlab::CommitsCalendar.get_commits_for_date(projects, @user, date) + else + @calendar_activities = {} + end + + # get the total number of unique commits + @commit_count = @calendar_activities.values.flatten.map(&:id).uniq.count + + @calendar_date = date + + render 'calendar_activities', layout: false + end + def determine_layout if current_user 'navless' diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 779cebc0136..c9fd0f0362b 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -96,7 +96,7 @@ module EventsHelper end end elsif event.push? - if event.push_with_commits? + if event.push_with_commits? && event.md_ref? if event.commits_count > 1 namespace_project_compare_url(event.project.namespace, event.project, from: event.commit_from, to: diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 2225b110651..a14277180c7 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -232,12 +232,45 @@ module ProjectsHelper end def contribution_guide_url(project) - if project && project.repository.contribution_guide + if project && contribution_guide = project.repository.contribution_guide namespace_project_blob_path( project.namespace, project, tree_join(project.default_branch, - project.repository.contribution_guide.name) + contribution_guide.name) + ) + end + end + + def changelog_url(project) + if project && changelog = project.repository.changelog + namespace_project_blob_path( + project.namespace, + project, + tree_join(project.default_branch, + changelog.name) + ) + end + end + + def license_url(project) + if project && license = project.repository.license + namespace_project_blob_path( + project.namespace, + project, + tree_join(project.default_branch, + license.name) + ) + end + end + + def version_url(project) + if project && version = project.repository.version + namespace_project_blob_path( + project.namespace, + project, + tree_join(project.default_branch, + version.name) ) end end diff --git a/app/models/event.rb b/app/models/event.rb index 8d20d7ef252..2103a48a71b 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -247,7 +247,7 @@ class Event < ActiveRecord::Base end def push_with_commits? - md_ref? && commits.any? && commit_from && commit_to + !commits.empty? && commit_from && commit_to end def last_push_to_non_root? diff --git a/app/models/project_contributions.rb b/app/models/project_contributions.rb index 8ab2d814a94..bfe9928b158 100644 --- a/app/models/project_contributions.rb +++ b/app/models/project_contributions.rb @@ -17,6 +17,15 @@ class ProjectContributions end end + def user_commits_on_date(date) + repository = @project.repository + + if !repository.exists? || repository.empty? + return [] + end + commits = repository.commits_by_user_on_date_log(@user, date) + end + def cache_key "#{Date.today.to_s}-commits-log-#{project.id}-#{user.email}" end diff --git a/app/models/repository.rb b/app/models/repository.rb index 47758b8ad68..c6eaa485b8a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -122,7 +122,7 @@ class Repository def expire_cache %i(size branch_names tag_names commit_count graph_log - readme version contribution_guide).each do |key| + readme version contribution_guide changelog license).each do |key| cache.expire(key) end end @@ -157,6 +157,20 @@ class Repository end end + def commits_by_user_on_date_log(user, date) + # format the date string for git + start_date = date.strftime("%Y-%m-%d 00:00:00") + end_date = date.strftime("%Y-%m-%d 23:59:59") + + author_emails = '(' + user.all_emails.map{ |e| Regexp.escape(e) }.join('|') + ')' + args = %W(git log -E --author=#{author_emails} --after=#{start_date.to_s} --until=#{end_date.to_s} --branches --pretty=format:%h) + commits = Gitlab::Popen.popen(args, path_to_repo).first.split("\n") + + commits.map! do |commit_id| + commit(commit_id) + end + end + def commits_per_day_for_user(user) timestamps_by_user_log(user). group_by { |commit_date| commit_date }. @@ -197,7 +211,27 @@ class Repository end def contribution_guide - cache.fetch(:contribution_guide) { tree(:head).contribution_guide } + cache.fetch(:contribution_guide) do + tree(:head).blobs.find do |file| + file.contributing? + end + end + end + + def changelog + cache.fetch(:changelog) do + tree(:head).blobs.find do |file| + file.name =~ /^(changelog|history)/i + end + end + end + + def license + cache.fetch(:license) do + tree(:head).blobs.find do |file| + file.name =~ /^license/i + end + end end def head_commit diff --git a/app/models/tree.rb b/app/models/tree.rb index 4f5d81f0a5e..f279e896cda 100644 --- a/app/models/tree.rb +++ b/app/models/tree.rb @@ -1,38 +1,38 @@ class Tree include Gitlab::MarkdownHelper - attr_accessor :entries, :readme, :contribution_guide + attr_accessor :repository, :sha, :path, :entries def initialize(repository, sha, path = '/') path = '/' if path.blank? - git_repo = repository.raw_repository - @entries = Gitlab::Git::Tree.where(git_repo, sha, path) - - available_readmes = @entries.select(&:readme?) - - if available_readmes.count > 0 - # If there is more than 1 readme in tree, find readme which is supported - # by markup renderer. - if available_readmes.length > 1 - supported_readmes = available_readmes.select do |readme| - previewable?(readme.name) - end - - # Take the first supported readme, or the first available readme, if we - # don't support any of them - readme_tree = supported_readmes.first || available_readmes.first - else - readme_tree = available_readmes.first - end - - readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name) - @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path) - end + + @repository = repository + @sha = sha + @path = path + + git_repo = @repository.raw_repository + @entries = Gitlab::Git::Tree.where(git_repo, @sha, @path) + end + + def readme + return @readme if defined?(@readme) - if contribution_tree = @entries.find(&:contributing?) - contribution_path = path == '/' ? contribution_tree.name : File.join(path, contribution_tree.name) - @contribution_guide = Gitlab::Git::Blob.find(git_repo, sha, contribution_path) + available_readmes = blobs.select(&:readme?) + + if available_readmes.count == 0 + return @readme = nil end + + # Take the first previewable readme, or the first available readme, if we + # can't preview any of them + readme_tree = available_readmes.find do |readme| + previewable?(readme.name) + end || available_readmes.first + + readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name) + + git_repo = repository.raw_repository + @readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path) end def trees diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml index 781600a3766..edfcccfcf4c 100644 --- a/app/views/admin/application_settings/_form.html.haml +++ b/app/views/admin/application_settings/_form.html.haml @@ -12,13 +12,13 @@ .checkbox = f.label :signup_enabled do = f.check_box :signup_enabled - Signin enabled + Signup enabled .form-group .col-sm-offset-2.col-sm-10 .checkbox = f.label :signin_enabled do = f.check_box :signin_enabled - Signup enabled + Signin enabled .form-group .col-sm-offset-2.col-sm-10 .checkbox diff --git a/app/views/events/event/_push.html.haml b/app/views/events/event/_push.html.haml index 489138887ae..60d7978b13f 100644 --- a/app/views/events/event/_push.html.haml +++ b/app/views/events/event/_push.html.haml @@ -21,5 +21,11 @@ %li.commits-stat - if event.commits_count > 2 %span ... and #{event.commits_count - 2} more commits. - = link_to namespace_project_compare_path(event.project.namespace, event.project, from: event.commit_from, to: event.commit_to) do - %strong Compare → #{truncate_sha(event.commit_from)}...#{truncate_sha(event.commit_to)} + - if event.md_ref? + - from = event.commit_from + - from_label = truncate_sha(from) + - else + - from = event.project.default_branch + - from_label = from + = link_to namespace_project_compare_path(event.project.namespace, event.project, from: from, to: event.commit_to) do + %strong Compare → #{from_label}...#{truncate_sha(event.commit_to)} diff --git a/app/views/projects/_issuable_form.html.haml b/app/views/projects/_issuable_form.html.haml index a7cd129b631..7fd5fe8a6e1 100644 --- a/app/views/projects/_issuable_form.html.haml +++ b/app/views/projects/_issuable_form.html.haml @@ -71,10 +71,10 @@ = link_to 'Create new label', new_namespace_project_label_path(issuable.project.namespace, issuable.project), target: :blank .form-actions - - if !issuable.project.empty_repo? && contribution_guide_url(issuable.project) && !issuable.persisted? + - if !issuable.project.empty_repo? && (guide_url = contribution_guide_url(issuable.project)) && !issuable.persisted? %p Please review the - %strong #{link_to 'guidelines for contribution', contribution_guide_url(issuable.project)} + %strong #{link_to 'guidelines for contribution', guide_url} to this repository. - if issuable.new_record? = f.submit "Submit new #{issuable.class.model_name.human.downcase}", class: 'btn btn-create' diff --git a/app/views/projects/diffs/_file.html.haml b/app/views/projects/diffs/_file.html.haml index 36d98b26712..a9e4d63cd98 100644 --- a/app/views/projects/diffs/_file.html.haml +++ b/app/views/projects/diffs/_file.html.haml @@ -22,11 +22,6 @@ .diff-btn-group - if blob.text? - - unless params[:view] == 'parallel' - %label - = check_box_tag nil, 1, false, class: 'js-toggle-diff-line-wrap' - Wrap text - = link_to '#', class: 'js-toggle-diff-comments btn btn-sm' do %i.fa.fa-chevron-down Show/Hide comments @@ -39,7 +34,7 @@ = view_file_btn(@commit.id, diff_file, project) - .diff-content + .diff-content.diff-wrap-lines -# Skipp all non non-supported blobs - return unless blob.respond_to?('text?') - if blob.text? diff --git a/app/views/projects/merge_requests/_new_submit.html.haml b/app/views/projects/merge_requests/_new_submit.html.haml index bf80afe8785..1d8eef4e8ce 100644 --- a/app/views/projects/merge_requests/_new_submit.html.haml +++ b/app/views/projects/merge_requests/_new_submit.html.haml @@ -69,10 +69,10 @@ = link_to 'Create new label', new_namespace_project_label_path(@merge_request.target_project.namespace, @merge_request.target_project), target: :blank .form-actions - - if contribution_guide_url(@target_project) + - if guide_url = contribution_guide_url(@target_project) %p Please review the - %strong #{link_to 'guidelines for contribution', contribution_guide_url(@target_project)} + %strong #{link_to 'guidelines for contribution', guide_url} to this repository. = f.hidden_field :source_project_id = f.hidden_field :source_branch diff --git a/app/views/projects/show.html.haml b/app/views/projects/show.html.haml index 74b07395650..822e67c5616 100644 --- a/app/views/projects/show.html.haml +++ b/app/views/projects/show.html.haml @@ -47,15 +47,26 @@ = link_to @project.forked_from_project.name_with_namespace, namespace_project_path(@project.namespace, @project.forked_from_project) - unless @project.empty_repo? - = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: @ref || @repository.root_ref), class: 'btn btn-block' do - Compare code - - - if @repository.version - - version = @repository.version - = link_to namespace_project_blob_path(@project.namespace, @project, tree_join(@repository.root_ref, version.name)), class: 'btn btn-block' do + - if version = @repository.version + - detail_url = changelog_url(@project) || version_url(@project) + = link_to detail_url, class: 'btn btn-block' do Version: %span.count = @repository.blob_by_oid(version.id).data + - elsif @repository.changelog + = link_to changelog_url(@project), class: 'btn btn-block' do + View changelog + + - if @repository.contribution_guide + = link_to contribution_guide_url(@project), class: 'btn btn-block' do + View contribution guide + + - if @repository.license + = link_to license_url(@project), class: 'btn btn-block' do + View license + + = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: @ref || @repository.root_ref), class: 'btn btn-block' do + Compare code .prepend-top-10 %p diff --git a/app/views/users/calendar.html.haml b/app/views/users/calendar.html.haml index 1d1c974da24..d113ceeb753 100644 --- a/app/views/users/calendar.html.haml +++ b/app/views/users/calendar.html.haml @@ -4,5 +4,6 @@ new calendar( #{@timestamps.to_json}, #{@starting_year}, - #{@starting_month} + #{@starting_month}, + '#{user_calendar_activities_path}' ); diff --git a/app/views/users/calendar_activities.html.haml b/app/views/users/calendar_activities.html.haml new file mode 100644 index 00000000000..7c0cecfadb5 --- /dev/null +++ b/app/views/users/calendar_activities.html.haml @@ -0,0 +1,33 @@ +.calendar_commit_activity + %hr + %h4 + Commit Activity + %strong + - if @commit_count == 0 + no + - else + = @commit_count + %span.calendar_commit_date + unique + = 'commit'.pluralize(@commit_count) + on + = @calendar_date.strftime("%b %d, %Y") rescue '' + -unless @commit_count == 0 + %hr + - @calendar_activities.each do |project, commits| + - next if commits.empty? + %div.js-toggle-container + %strong + = pluralize(commits.count, 'commit') + in project + = link_to project.name_with_namespace, project_path(project) + %a.text-expander.js-toggle-button … + %hr + %div.js-toggle-content + - commits.each do |commit| + %span.monospace + = commit.committed_date.strftime("%H:%M") + = link_to commit.short_id, namespace_project_commit_path(project.namespace, project, commit), class: "commit_short_id" + = link_to commit.message, namespace_project_commit_path(project.namespace, project, commit), class: "commit-row-message str-truncated" + %br + %hr diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml index abd6b229782..6d6beb58711 100644 --- a/app/views/users/show.html.haml +++ b/app/views/users/show.html.haml @@ -25,6 +25,7 @@ .user-calendar %h4.center.light %i.fa.fa-spinner.fa-spin + .user-calendar-activities %hr %h4 User Activity diff --git a/config/routes.rb b/config/routes.rb index e65ef30afb7..0950bed3cf1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -198,7 +198,10 @@ Gitlab::Application.routes.draw do end get 'u/:username/calendar' => 'users#calendar', as: :user_calendar, - constraints: { username: /(?:[^.]|\.(?!atom$))+/, format: /atom/ } + constraints: { username: /.*/ } + + get 'u/:username/calendar_activities' => 'users#calendar_activities', as: :user_calendar_activities, + constraints: { username: /.*/ } get '/u/:username' => 'users#show', as: :user, constraints: { username: /(?:[^.]|\.(?!atom$))+/, format: /atom/ } diff --git a/db/schema.rb b/db/schema.rb index e7dccbad4f9..1be3782dcb3 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -458,7 +458,6 @@ ActiveRecord::Schema.define(version: 20150313012111) do t.integer "notification_level", default: 1, null: false t.datetime "password_expires_at" t.integer "created_by_id" - t.datetime "last_credential_check_at" t.string "avatar" t.string "confirmation_token" t.datetime "confirmed_at" @@ -466,6 +465,7 @@ ActiveRecord::Schema.define(version: 20150313012111) do t.string "unconfirmed_email" t.boolean "hide_no_ssh_key", default: false t.string "website_url", default: "", null: false + t.datetime "last_credential_check_at" t.string "github_access_token" t.string "gitlab_access_token" t.string "notification_email" diff --git a/lib/gitlab/commits_calendar.rb b/lib/gitlab/commits_calendar.rb index 2f30d238e6b..8963d346b6f 100644 --- a/lib/gitlab/commits_calendar.rb +++ b/lib/gitlab/commits_calendar.rb @@ -22,6 +22,14 @@ module Gitlab end end + def self.get_commits_for_date(projects, user, date) + user_commits = {} + projects.reject(&:forked?).each do |project| + user_commits[project] = ProjectContributions.new(project, user).user_commits_on_date(date) + end + user_commits + end + def starting_year (Time.now - 1.year).strftime("%Y") end diff --git a/lib/gitlab/push_data_builder.rb b/lib/gitlab/push_data_builder.rb index ea9012b8844..694a30db5df 100644 --- a/lib/gitlab/push_data_builder.rb +++ b/lib/gitlab/push_data_builder.rb @@ -27,6 +27,12 @@ module Gitlab # Get latest 20 commits ASC commits_limited = commits.last(20) + + # For performance purposes maximum 20 latest commits + # will be passed as post receive hook data. + commit_attrs = commits_limited.map do |commit| + commit.hook_attrs(project) + end type = Gitlab::Git.tag_ref?(ref) ? "tag_push" : "push" # Hash to be passed as post_receive_data @@ -49,17 +55,10 @@ module Gitlab git_ssh_url: project.ssh_url_to_repo, visibility_level: project.visibility_level }, - commits: [], + commits: commit_attrs, total_commits_count: commits_count } - # For performance purposes maximum 20 latest commits - # will be passed as post receive hook data. - commits_limited.each do |commit| - data[:commits] << commit.hook_attrs(project) - end - - data[:commits] = "" if data[:commits].count == 0 data end diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 44225c054f2..7962bcdde71 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -1,27 +1,59 @@ require 'spec_helper' describe UsersController do - let(:user) { create(:user, username: "user1", name: "User 1", email: "user1@gitlab.com") } + let(:user) { create(:user, username: 'user1', name: 'User 1', email: 'user1@gitlab.com') } before do sign_in(user) end - describe "GET #show" do + describe 'GET #show' do render_views - it "renders the show template" do + it 'renders the show template' do get :show, username: user.username expect(response.status).to eq(200) - expect(response).to render_template("show") + expect(response).to render_template('show') end end - describe "GET #calendar" do - it "renders calendar" do + describe 'GET #calendar' do + it 'renders calendar' do get :calendar, username: user.username - expect(response).to render_template("calendar") + expect(response).to render_template('calendar') end end -end + describe 'GET #calendar_activities' do + include RepoHelpers + let(:project) { create(:project) } + let(:calendar_user) { create(:user, email: sample_commit.author_email) } + let(:commit1) { '0ed8c6c6752e8c6ea63e7b92a517bf5ac1209c80' } + let(:commit2) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' } + + before do + allow_any_instance_of(User).to receive(:contributed_projects_ids).and_return([project.id]) + project.team << [user, :developer] + end + + it 'assigns @commit_count' do + get :calendar_activities, username: calendar_user.username, date: '2014-07-31' + expect(assigns(:commit_count)).to eq(2) + end + + it 'assigns @calendar_date' do + get :calendar_activities, username: calendar_user.username, date: '2014-07-31' + expect(assigns(:calendar_date)).to eq(Date.parse('2014-07-31')) + end + + it 'assigns @calendar_activities' do + get :calendar_activities, username: calendar_user.username, date: '2014-07-31' + expect(assigns(:calendar_activities).values.flatten.map(&:id)).to eq([commit1, commit2]) + end + + it 'renders calendar_activities' do + get :calendar_activities, username: calendar_user.username + expect(response).to render_template('calendar_activities') + end + end +end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index b3a38f6c5b9..0e3e0b167d7 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -29,7 +29,7 @@ describe Repository do subject { repository.timestamps_by_user_log(user) } - it { is_expected.to eq(["2014-08-06", "2014-07-31", "2014-07-31"]) } + it { is_expected.to eq(['2014-08-06', '2014-07-31', '2014-07-31']) } end describe 'multiple emails for user' do @@ -38,7 +38,22 @@ describe Repository do subject { repository.timestamps_by_user_log(user) } - it { is_expected.to eq(["2015-01-10", "2014-08-06", "2014-07-31", "2014-07-31"]) } + it { is_expected.to eq(['2015-01-10', '2014-08-06', '2014-07-31', '2014-07-31']) } + end + end + + context :commits_by_user_on_date_log do + + describe 'single e-mail for user' do + let(:user) { create(:user, email: sample_commit.author_email) } + let(:commit1) { '0ed8c6c6752e8c6ea63e7b92a517bf5ac1209c80' } + let(:commit2) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' } + + subject { repository.commits_by_user_on_date_log(user,Date.new(2014, 07, 31)) } + + it 'contains the exepected commits' do + expect(subject.flatten.map(&:id)).to eq([commit1, commit2]) + end end end end |
