else @merge_requests.opened
end
- @merge_requests = @merge_requests.includes(:author, :project)
+ @merge_requests = @merge_requests.includes(:author, :project).order("created_at desc")
end
def show
before_save :set_identifier
before_validation :strip_white_space
- after_save :update_repository
- after_destroy :repository_delete_key
delegate :name, :email, :to => :user, :prefix => true
validate :unique_key
--- /dev/null
+class KeyObserver < ActiveRecord::Observer
+ def after_save(key)
+ key.update_repository
+ end
+
+ def after_destroy(key)
+ key.repository_delete_key
+ end
+end
class Project < ActiveRecord::Base
belongs_to :owner, :class_name => "User"
- has_many :events, :dependent => :destroy
+ has_many :users, :through => :users_projects
+ has_many :events, :dependent => :destroy
has_many :merge_requests, :dependent => :destroy
- has_many :issues, :dependent => :destroy, :order => "position"
+ has_many :issues, :dependent => :destroy, :order => "position"
has_many :users_projects, :dependent => :destroy
- has_many :users, :through => :users_projects
- has_many :notes, :dependent => :destroy
- has_many :snippets, :dependent => :destroy
- has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key"
- has_many :web_hooks, :dependent => :destroy
+ has_many :notes, :dependent => :destroy
+ has_many :snippets, :dependent => :destroy
+ has_many :deploy_keys, :dependent => :destroy, :foreign_key => "project_id", :class_name => "Key"
+ has_many :web_hooks, :dependent => :destroy
+ has_many :wikis, :dependent => :destroy
has_many :protected_branches, :dependent => :destroy
- has_many :wikis, :dependent => :destroy
-
- acts_as_taggable
validates :name,
:uniqueness => true,
:message => "only letters, digits & '_' '-' '.' allowed" },
:length => { :within => 3..255 }
- validates :owner,
- :presence => true
-
+ validates :owner, :presence => true
validate :check_limit
validate :repo_name
- after_destroy :destroy_repository
- after_save :update_repository
-
attr_protected :private_flag, :owner_id
scope :public_only, where(:private_flag => false)
users_projects.find_by_user_id(user_id)
end
- def fresh_merge_requests(n)
- merge_requests.includes(:project, :author).order("created_at desc").first(n)
- end
-
- def fresh_issues(n)
- issues.includes(:project, :author).order("created_at desc").first(n)
- end
-
- def fresh_notes(n)
- notes.inc_author_project.order("created_at desc").first(n)
- end
-
def common_notes
notes.where(:noteable_type => ["", nil]).inc_author_project
end
end
def last_activity
- events.last
- rescue
- nil
+ events.last || nil
end
def last_activity_date
last_activity_date
end
- # Get project updates from cache
- # or calculate.
- def cached_updates(limit, expire = 2.minutes)
- activities_key = "project_#{id}_activities"
- cached_activities = Rails.cache.read(activities_key)
- if cached_activities
- activities = cached_activities
- else
- activities = updates(limit)
- Rails.cache.write(activities_key, activities, :expires_in => expire)
- end
-
- activities
- end
-
- # Get 20 events for project like
- # commits, issues or notes
- def updates(n = 3)
- [
- fresh_commits(n),
- fresh_issues(n),
- fresh_notes(n)
- ].compact.flatten.sort do |x, y|
- y.created_at <=> x.created_at
- end[0...n]
- end
-
- def activities(n=3)
- [
- fresh_issues(n),
- fresh_merge_requests(n),
- notes.inc_author_project.where("noteable_type is not null").order("created_at desc").first(n)
- ].compact.flatten.sort do |x, y|
- y.created_at <=> x.created_at
- end[0...n]
- end
-
def check_limit
unless owner.can_create_project?
errors[:base] << ("Your own projects limit is #{owner.projects_limit}! Please contact administrator to increase it")
--- /dev/null
+class ProjectObserver < ActiveRecord::Observer
+ def after_save(project)
+ project.update_repository
+ end
+
+ def after_destroy(project)
+ project.destroy_repository
+ end
+end
%li= msg
.clearfix
+ = f.label :title
+ .input= f.text_area :title, :maxlength => 255, :class => "xxlarge"
+
+ .clearfix
= f.label :assignee_id
.input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" })
= f.label :closed
.input= f.check_box :closed
- .clearfix
- = f.label :title
- .input= f.text_area :title, :maxlength => 255, :class => "xxlarge"
.actions
= f.submit 'Save', :class => "primary btn"
= link_to "Cancel", project_issues_path(@project), :class => "btn"
- else
= link_to "Cancel", project_issue_path(@project, @issue), :class => "btn"
-
-
- - unless @issue.new_record?
- .right
- = link_to 'Remove', [@project, @issue], :confirm => 'Are you sure?', :method => :delete, :class => "danger btn"
- else
= link_to 'Resolve', project_issue_path(issue.project, issue, :issue => {:closed => true }, :status_only => true), :method => :put, :class => "success btn small", :remote => true
= link_to 'Edit', edit_project_issue_path(issue.project, issue), :class => "btn small edit-issue-link", :remote => true
- -#- if can?(current_user, :admin_issue, @project) || issue.author == current_user
- = link_to 'Remove', [issue.project, issue], :confirm => 'Are you sure?', :method => :delete, :remote => true, :class => "danger btn small delete-issue", :id => "destroy_issue_#{issue.id}"
= image_tag gravatar_icon(issue.assignee_email), :class => "avatar"
%span.update-author
assigned to
%li= msg
.clearfix
+ = f.label :title
+ .input= f.text_area :title, :class => "xxlarge", :maxlength => 255, :rows => 5
+ .clearfix
= f.label :source_branch, "From"
.input= f.select(:source_branch, @project.heads.map(&:name), { :include_blank => "Select branch" }, :style => "width:250px")
.clearfix
= f.label :assignee_id, "Assign to"
.input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { :include_blank => "Select user" }, :style => "width:250px")
- .clearfix
- = f.label :title
- .input= f.text_area :title, :class => "xlarge", :maxlength => 255, :rows => 5
.actions
= f.submit 'Save', :class => "primary btn"
- if @merge_request.new_record?
- else
= link_to project_merge_request_path(@project, @merge_request), :class => "btn" do
Cancel
-
- - unless @merge_request.new_record?
- .right
- = link_to 'Remove', [@project, @merge_request], :confirm => 'Are you sure?', :method => :delete, :class => "btn danger"
-
-- unless @projects.empty?
- .row
- .span4
- %div.leftbar.ui-box
- %h5
- Projects
- - if current_user.can_create_project?
- %span.right
- = link_to new_project_path, :class => "btn very_small info" do
- New Project
- .content_list
- - @projects.each do |project|
- = link_to project_path(project), :remote => true, :class => dom_class(project) do
- %h4
- %span.ico.project
- = truncate(project.name, :length => 22)
- .span12.right
- .show_holder.ui-box.padded
- .loading
-
-- else
- %h2 Nothing here
+.row
+ .span4
+ %div.leftbar.ui-box
+ %h5
+ Projects
+ - if current_user.can_create_project?
+ %span.right
+ = link_to new_project_path, :class => "btn very_small info" do
+ New Project
+ .content_list
+ - @projects.each do |project|
+ = link_to project_path(project), :remote => true, :class => dom_class(project) do
+ %h4
+ %span.ico.project
+ = truncate(project.name, :length => 22)
+ .span12.right
+ .show_holder.ui-box.padded
+ .loading
:javascript
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
# Activate observers that should always be running.
- config.active_record.observers = :mailer_observer, :activity_observer
+ config.active_record.observers = :mailer_observer, :activity_observer, :project_observer, :key_observer
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
t.integer "action"
end
- create_table "features", :force => true do |t|
- t.string "name"
- t.string "branch_name"
- t.integer "assignee_id"
- t.integer "author_id"
- t.integer "project_id"
- t.datetime "created_at"
- t.datetime "updated_at"
- t.string "version"
- t.integer "status", :default => 0, :null => false
- end
-
create_table "issues", :force => true do |t|
t.string "title"
t.integer "assignee_id"
t.integer "author_id"
t.integer "project_id"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.boolean "closed", :default => false, :null => false
t.integer "position", :default => 0
t.boolean "critical", :default => false, :null => false
create_table "keys", :force => true do |t|
t.integer "user_id"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.text "key"
t.string "title"
t.string "identifier"
t.integer "assignee_id"
t.string "title"
t.boolean "closed", :default => false, :null => false
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
add_index "merge_requests", ["project_id"], :name => "index_merge_requests_on_project_id"
t.string "noteable_id"
t.string "noteable_type"
t.integer "author_id"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.integer "project_id"
t.string "attachment"
t.string "line_code"
t.string "name"
t.string "path"
t.text "description"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.boolean "private_flag", :default => true, :null => false
t.string "code"
t.integer "owner_id"
t.text "content"
t.integer "author_id", :null => false
t.integer "project_id", :null => false
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.string "file_name"
t.datetime "expires_at"
end
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.string "name"
t.boolean "admin", :default => false, :null => false
t.integer "projects_limit", :default => 10
create_table "users_projects", :force => true do |t|
t.integer "user_id", :null => false
t.integer "project_id", :null => false
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
t.integer "project_access", :default => 0, :null => false
end
create_table "web_hooks", :force => true do |t|
t.string "url"
t.integer "project_id"
- t.datetime "created_at"
- t.datetime "updated_at"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
end
create_table "wikis", :force => true do |t|
describe Project do
describe "Associations" do
- it { should have_many(:events) }
it { should have_many(:users) }
- it { should have_many(:users_projects) }
- it { should have_many(:issues) }
- it { should have_many(:notes) }
- it { should have_many(:snippets) }
+ it { should have_many(:protected_branches).dependent(:destroy) }
+ it { should have_many(:events).dependent(:destroy) }
+ it { should have_many(:wikis).dependent(:destroy) }
+ it { should have_many(:merge_requests).dependent(:destroy) }
+ it { should have_many(:users_projects).dependent(:destroy) }
+ it { should have_many(:issues).dependent(:destroy) }
+ it { should have_many(:notes).dependent(:destroy) }
+ it { should have_many(:snippets).dependent(:destroy) }
it { should have_many(:web_hooks).dependent(:destroy) }
+ it { should have_many(:deploy_keys).dependent(:destroy) }
end
describe "Validation" do
end
end
- describe "updates" do
- let(:project) { Factory :project }
-
- before do
- @issue = Factory :issue,
- :project => project,
- :author => Factory(:user),
- :assignee => Factory(:user)
-
- @note = Factory :note,
- :project => project,
- :author => Factory(:user)
-
- @commit = project.fresh_commits(1).first
- end
-
- describe "return commit, note & issue" do
- it { project.updates(3).count.should == 3 }
- it { project.updates(3).last.id.should == @commit.id }
- it { project.updates(3).include?(@issue).should be_true }
- it { project.updates(3).include?(@note).should be_true }
- end
- end
-
describe "last_activity" do
let(:project) { Factory :project }
page.body.should have_selector("entry summary", :text => @issue.title)
end
- describe "Destroy" do
- before do
- # admin access to remove issue
- @user.users_projects.destroy_all
- project.add_access(@user, :read, :write, :admin)
- visit edit_project_issue_path(project, @issue)
- end
-
- it "should remove entry" do
- expect {
- click_link "Remove"
- }.to change { Issue.count }.by(-1)
- end
- end
-
describe "statuses" do
before do
@closed_issue = Factory :issue,