Commit 1a9531c9a42e380d922de98ad1658e85ac5fbde6
1 parent
29e11d14
Exists in
master
and in
4 other branches
fix #140, commit lil refactor
Showing
5 changed files
with
59 additions
and
38 deletions
Show diff stats
app/models/project.rb
| ... | ... | @@ -36,6 +36,8 @@ class Project < ActiveRecord::Base |
| 36 | 36 | |
| 37 | 37 | validate :check_limit |
| 38 | 38 | |
| 39 | + validate :repo_name | |
| 40 | + | |
| 39 | 41 | after_destroy :destroy_gitosis_project |
| 40 | 42 | after_save :update_gitosis_project |
| 41 | 43 | |
| ... | ... | @@ -168,6 +170,12 @@ class Project < ActiveRecord::Base |
| 168 | 170 | errors[:base] << ("Cant check your ability to create project") |
| 169 | 171 | end |
| 170 | 172 | |
| 173 | + def repo_name | |
| 174 | + if path == "gitosis-admin" | |
| 175 | + errors.add(:path, "Project path like 'gitosis-admin' is not allowed") | |
| 176 | + end | |
| 177 | + end | |
| 178 | + | |
| 171 | 179 | def valid_repo? |
| 172 | 180 | repo |
| 173 | 181 | rescue | ... | ... |
app/views/commits/_diff.html.haml
| 1 | -.file_stats | |
| 2 | - - @commit.diffs.each do |diff| | |
| 3 | - - if diff.deleted_file | |
| 4 | - %span.removed_file | |
| 5 | - %a{:href => "##{diff.a_path}"} | |
| 6 | - = diff.a_path | |
| 7 | - = image_tag "blueprint_delete.png" | |
| 8 | - - elsif diff.renamed_file | |
| 9 | - %span.moved_file | |
| 10 | - %a{:href => "##{diff.b_path}"} | |
| 11 | - = diff.a_path | |
| 12 | - = "->" | |
| 13 | - = diff.b_path | |
| 14 | - = image_tag "blueprint_notice.png" | |
| 15 | - - elsif diff.new_file | |
| 16 | - %span.new_file | |
| 17 | - %a{:href => "##{diff.b_path}"} | |
| 18 | - = diff.b_path | |
| 19 | - = image_tag "blueprint_add.png" | |
| 20 | - - else | |
| 21 | - %span.edit_file | |
| 22 | - %a{:href => "##{diff.b_path}"} | |
| 23 | - = diff.b_path | |
| 24 | - = image_tag "blueprint_info.png" | |
| 1 | +.file_stats= render "commits/diff_head" | |
| 2 | + | |
| 25 | 3 | - @commit.diffs.each do |diff| |
| 26 | 4 | - next if diff.diff.empty? |
| 27 | 5 | - file = (@commit.tree / diff.b_path) |
| ... | ... | @@ -36,20 +14,7 @@ |
| 36 | 14 | %br/ |
| 37 | 15 | .diff_file_content |
| 38 | 16 | - if file.text? |
| 39 | - - lines_arr = diff.diff.lines.to_a | |
| 40 | - - line_old = lines_arr[2].match(/-(\d)/)[0].to_i.abs rescue 0 | |
| 41 | - - line_new = lines_arr[2].match(/\+(\d)/)[0].to_i.abs rescue 0 | |
| 42 | - - lines = lines_arr[3..-1].join | |
| 43 | - - lines.each_line do |line| | |
| 44 | - = diff_line(line, line_new, line_old) | |
| 45 | - - if line[0] == "+" | |
| 46 | - - line_new += 1 | |
| 47 | - - elsif | |
| 48 | - - line[0] == "-" | |
| 49 | - - line_old += 1 | |
| 50 | - - else | |
| 51 | - - line_new += 1 | |
| 52 | - - line_old += 1 | |
| 17 | + = render :partial => "commits/text_file", :locals => { :diff => diff } | |
| 53 | 18 | - elsif file.image? |
| 54 | 19 | .diff_file_content_image |
| 55 | 20 | %img{:src => "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} | ... | ... |
| ... | ... | @@ -0,0 +1,24 @@ |
| 1 | +- @commit.diffs.each do |diff| | |
| 2 | + - if diff.deleted_file | |
| 3 | + %span.removed_file | |
| 4 | + %a{:href => "##{diff.a_path}"} | |
| 5 | + = diff.a_path | |
| 6 | + = image_tag "blueprint_delete.png" | |
| 7 | + - elsif diff.renamed_file | |
| 8 | + %span.moved_file | |
| 9 | + %a{:href => "##{diff.b_path}"} | |
| 10 | + = diff.a_path | |
| 11 | + = "->" | |
| 12 | + = diff.b_path | |
| 13 | + = image_tag "blueprint_notice.png" | |
| 14 | + - elsif diff.new_file | |
| 15 | + %span.new_file | |
| 16 | + %a{:href => "##{diff.b_path}"} | |
| 17 | + = diff.b_path | |
| 18 | + = image_tag "blueprint_add.png" | |
| 19 | + - else | |
| 20 | + %span.edit_file | |
| 21 | + %a{:href => "##{diff.b_path}"} | |
| 22 | + = diff.b_path | |
| 23 | + = image_tag "blueprint_info.png" | |
| 24 | + | ... | ... |
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +- lines_arr = diff.diff.lines.to_a | |
| 2 | +- line_old = lines_arr[2].match(/-(\d)/)[0].to_i.abs rescue 0 | |
| 3 | +- line_new = lines_arr[2].match(/\+(\d)/)[0].to_i.abs rescue 0 | |
| 4 | +- lines = lines_arr[3..-1].join | |
| 5 | +- lines.each_line do |line| | |
| 6 | + = diff_line(line, line_new, line_old) | |
| 7 | + - if line[0] == "+" | |
| 8 | + - line_new += 1 | |
| 9 | + - elsif | |
| 10 | + - line[0] == "-" | |
| 11 | + - line_old += 1 | |
| 12 | + - else | |
| 13 | + - line_new += 1 | |
| 14 | + - line_old += 1 | |
| 15 | + | ... | ... |
spec/models/project_spec.rb
| ... | ... | @@ -4,11 +4,15 @@ describe Project do |
| 4 | 4 | describe "Associations" do |
| 5 | 5 | it { should have_many(:users) } |
| 6 | 6 | it { should have_many(:users_projects) } |
| 7 | + it { should have_many(:issues) } | |
| 8 | + it { should have_many(:notes) } | |
| 9 | + it { should have_many(:snippets) } | |
| 7 | 10 | end |
| 8 | 11 | |
| 9 | 12 | describe "Validation" do |
| 10 | 13 | it { should validate_presence_of(:name) } |
| 11 | 14 | it { should validate_presence_of(:path) } |
| 15 | + it { should validate_presence_of(:code) } | |
| 12 | 16 | end |
| 13 | 17 | |
| 14 | 18 | describe "Respond to" do |
| ... | ... | @@ -31,6 +35,11 @@ describe Project do |
| 31 | 35 | it { should respond_to(:commit) } |
| 32 | 36 | end |
| 33 | 37 | |
| 38 | + it "should not allow 'gitosis-admin' as repo name" do | |
| 39 | + should allow_value("blah").for(:path) | |
| 40 | + should_not allow_value("gitosis-admin").for(:path) | |
| 41 | + end | |
| 42 | + | |
| 34 | 43 | it "should return valid url to repo" do |
| 35 | 44 | project = Project.new(:path => "somewhere") |
| 36 | 45 | project.url_to_repo.should == "git@localhost:somewhere.git" | ... | ... |