Commit f4e3ec29c46752c68b99fa2eb37cfb12463de9f2

Authored by Dmitriy Zaporozhets
1 parent 3d7b35a3

fixed commit commenting

app/models/key.rb
... ... @@ -55,11 +55,12 @@ end
55 55 # Table name: keys
56 56 #
57 57 # id :integer not null, primary key
58   -# user_id :integer not null
  58 +# user_id :integer
59 59 # created_at :datetime
60 60 # updated_at :datetime
61 61 # key :text
62 62 # title :string(255)
63 63 # identifier :string(255)
  64 +# project_id :integer
64 65 #
65 66  
... ...
app/models/note.rb
... ... @@ -88,5 +88,6 @@ end
88 88 # updated_at :datetime
89 89 # project_id :integer
90 90 # attachment :string(255)
  91 +# line_code :string(255)
91 92 #
92 93  
... ...
db/migrate/20120121122616_fix_noteable_id.rb 0 → 100644
... ... @@ -0,0 +1,9 @@
  1 +class FixNoteableId < ActiveRecord::Migration
  2 + def up
  3 + change_column :notes, :noteable_id, :string, :limit => 255
  4 + end
  5 +
  6 + def down
  7 + change_column :notes, :noteable_id, :integer, :limit => 11
  8 + end
  9 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,19 @@
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(:version => 20120119203233) do
  14 +ActiveRecord::Schema.define(:version => 20120121122616) do
  15 +
  16 + create_table "features", :force => true do |t|
  17 + t.string "name"
  18 + t.string "branch_name"
  19 + t.integer "assignee_id"
  20 + t.integer "author_id"
  21 + t.integer "project_id"
  22 + t.datetime "created_at"
  23 + t.datetime "updated_at"
  24 + t.string "version"
  25 + t.integer "status", :default => 0, :null => false
  26 + end
15 27  
16 28 create_table "issues", :force => true do |t|
17 29 t.string "title"
... ... @@ -54,7 +66,7 @@ ActiveRecord::Schema.define(:version =&gt; 20120119203233) do
54 66  
55 67 create_table "notes", :force => true do |t|
56 68 t.text "note"
57   - t.integer "noteable_id", :limit => 255
  69 + t.string "noteable_id"
58 70 t.string "noteable_type"
59 71 t.integer "author_id"
60 72 t.datetime "created_at"
... ...
spec/models/key_spec.rb
... ... @@ -22,11 +22,12 @@ end
22 22 # Table name: keys
23 23 #
24 24 # id :integer not null, primary key
25   -# user_id :integer not null
  25 +# user_id :integer
26 26 # created_at :datetime
27 27 # updated_at :datetime
28 28 # key :text
29 29 # title :string(255)
30 30 # identifier :string(255)
  31 +# project_id :integer
31 32 #
32 33  
... ...
spec/models/note_spec.rb
1 1 require 'spec_helper'
2 2  
3 3 describe Note do
  4 + let(:project) { Factory :project }
  5 + let!(:commit) { project.commit }
  6 +
4 7 describe "Associations" do
5 8 it { should belong_to(:project) }
6 9 end
... ... @@ -11,16 +14,60 @@ describe Note do
11 14 end
12 15  
13 16 it { Factory.create(:note,
14   - :project => Factory.create(:project)).should be_valid }
  17 + :project => project).should be_valid }
15 18 describe "Scopes" do
16 19 it "should have a today named scope that returns ..." do
17 20 Note.today.where_values.should == ["created_at >= '#{Date.today}'"]
18 21 end
19 22 end
20   -
  23 +
  24 + describe "Commit notes" do
  25 +
  26 + before do
  27 + @note = Factory :note,
  28 + :project => project,
  29 + :noteable_id => commit.id,
  30 + :noteable_type => "Commit"
  31 + end
  32 +
  33 + it "should save a valid note" do
  34 + @note.noteable_id.should == commit.id
  35 + @note.target.id.should == commit.id
  36 + end
  37 + end
  38 +
  39 + describe "Pre-line commit notes" do
  40 + before do
  41 + @note = Factory :note,
  42 + :project => project,
  43 + :noteable_id => commit.id,
  44 + :noteable_type => "Commit",
  45 + :line_code => "OLD_1_23"
  46 + end
  47 +
  48 + it "should save a valid note" do
  49 + @note.noteable_id.should == commit.id
  50 + @note.target.id.should == commit.id
  51 + end
  52 +
  53 + it { @note.line_type_id.should == "OLD" }
  54 + it { @note.line_file_id.should == 1 }
  55 + it { @note.line_number.should == 23 }
  56 +
  57 + it { @note.for_line?(1, 23, 34).should be_true }
  58 + it { @note.for_line?(1, 23, nil).should be_true }
  59 + it { @note.for_line?(1, 23, 0).should be_true }
  60 + it { @note.for_line?(1, 23, 23).should be_true }
  61 +
  62 + it { @note.for_line?(1, nil, 34).should be_false }
  63 + it { @note.for_line?(1, 24, nil).should be_false }
  64 + it { @note.for_line?(1, 24, 0).should be_false }
  65 + it { @note.for_line?(1, 24, 23).should be_false }
  66 + end
  67 +
21 68 describe :authorization do
22 69 before do
23   - @p1 = Factory :project
  70 + @p1 = project
24 71 @p2 = Factory :project, :code => "alien", :path => "legit_1"
25 72 @u1 = Factory :user
26 73 @u2 = Factory :user
... ... @@ -79,5 +126,6 @@ end
79 126 # updated_at :datetime
80 127 # project_id :integer
81 128 # attachment :string(255)
  129 +# line_code :string(255)
82 130 #
83 131  
... ...
spec/requests/commits_notes_spec.rb
... ... @@ -19,5 +19,10 @@ describe &quot;Issues&quot; do
19 19 it "should conatin new note" do
20 20 page.should have_content("I commented this commit")
21 21 end
  22 +
  23 + it "should be displayed when i visit this commit again" do
  24 + visit project_commit_path(project, commit)
  25 + page.should have_content("I commented this commit")
  26 + end
22 27 end
23 28 end
... ...