public
Description: Gitorious aims to provide a great way of doing distributed opensource code collaboration.
Homepage: http://gitorious.org/projects/gitorious
Clone URL: git://github.com/dysinger/gitorious.git
Search Repo:
Normalize url fields (eg add http:// if it aint there) on User+Project
dysinger (author)
Wed Apr 16 23:33:10 -0700 2008
commit  273408c2fcc519dd963104262cd5bc5dbac66426
tree    a761780f379e52949e103b03566b730b607f3748
parent  e3d32f65db71e5a52bb65daaa073672d420cba1f
...
46
47
48
49
50
51
52
...
46
47
48
 
49
50
51
0
@@ -46,7 +46,6 @@
0
 * improve commenting and comments visibility
0
 * handle mising/wrong SHA1s gracefully in browser
0
 * parse SHA1s in commits+comments
0
-* Normalize url fields (eg add http:// if it aint there) on User+Project
0
 * Detect renames etc when showing a commit
0
 * Always add a "mainline-upstream" branch that track the mainline repos automagically to clones
0
 ---
...
1
2
3
 
4
5
6
7
8
 
9
10
11
12
13
 
 
14
15
16
 
 
17
18
 
19
20
21
...
23
24
25
26
27
 
 
28
29
30
31
 
32
33
 
34
35
36
37
38
39
 
40
41
42
 
43
44
45
 
46
47
48
...
68
69
70
71
 
72
73
74
75
 
76
77
 
78
79
80
81
 
82
83
84
85
 
86
87
88
89
 
90
91
92
93
 
94
95
96
 
97
98
99
 
 
 
 
 
 
 
 
 
 
 
 
 
100
101
102
103
104
105
 
106
107
108
109
110
111
 
 
112
113
114
...
120
121
122
123
 
124
125
126
127
128
 
129
130
131
132
 
 
 
 
 
 
 
 
 
133
...
1
2
 
3
4
5
6
7
 
8
9
10
11
 
 
12
13
14
 
 
15
16
17
 
18
19
20
21
...
23
24
25
 
 
26
27
28
29
30
 
31
32
 
33
34
35
36
37
38
 
39
40
41
 
42
43
44
 
45
46
47
48
...
68
69
70
 
71
72
73
74
 
75
76
 
77
78
79
80
 
81
82
83
84
 
85
86
87
88
 
89
90
91
92
 
93
94
95
 
96
97
98
 
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 
117
118
119
120
121
 
 
122
123
124
125
126
...
132
133
134
 
135
136
137
138
139
 
140
141
142
143
 
144
145
146
147
148
149
150
151
152
153
0
@@ -1,21 +1,21 @@
0
 class Project < ActiveRecord::Base
0
   acts_as_taggable
0
-
0
+
0
   belongs_to :user
0
   has_many :comments, :dependent => :destroy
0
   has_many :repositories, :order => "repositories.mainline desc, repositories.created_at asc",
0
     :dependent => :destroy
0
- has_one :mainline_repository, :conditions => ["mainline = ?", true],
0
+ has_one :mainline_repository, :conditions => ["mainline = ?", true],
0
     :class_name => "Repository"
0
   has_many :repository_clones, :conditions => ["mainline = ?", false],
0
     :class_name => "Repository"
0
-
0
- is_indexed :fields => ["title", "description", "slug"],
0
+
0
+ is_indexed :fields => ["title", "description", "slug"],
0
     :concatenate => [
0
- { :class_name => 'Tag',
0
- :field => 'name',
0
+ { :class_name => 'Tag',
0
+ :field => 'name',
0
         :as => 'category',
0
- :association_sql => "LEFT OUTER JOIN taggings ON taggings.taggable_id = projects.id " +
0
+ :association_sql => "LEFT OUTER JOIN taggings ON taggings.taggable_id = projects.id " +
0
                             "AND taggings.taggable_type = 'Project' LEFT OUTER JOIN tags ON taggings.tag_id = tags.id"
0
       }],
0
     :include => [{
0
@@ -23,26 +23,26 @@ class Project < ActiveRecord::Base
0
       :field => "login",
0
       :as => "user"
0
     }]
0
-
0
-
0
+
0
+
0
   URL_FORMAT_RE = /^(http|https|nntp):\/\//.freeze
0
   validates_presence_of :title, :user_id, :slug
0
   validates_uniqueness_of :slug, :case_sensitive => false
0
- validates_format_of :slug, :with => /^[a-z0-9_\-]+$/i,
0
+ validates_format_of :slug, :with => /^[a-z0-9_\-]+$/i,
0
     :message => "must match something in the range of [a-z0-9_\-]+"
0
- validates_format_of :home_url, :with => URL_FORMAT_RE,
0
+ validates_format_of :home_url, :with => URL_FORMAT_RE,
0
     :if => proc{|record| !record.home_url.blank? },
0
     :message => "Must begin with http(s)"
0
   validates_format_of :mailinglist_url, :with => URL_FORMAT_RE,
0
     :if => proc{|record| !record.mailinglist_url.blank? },
0
     :message => "Must begin with http(s)"
0
- validates_format_of :bugtracker_url, :with => URL_FORMAT_RE,
0
+ validates_format_of :bugtracker_url, :with => URL_FORMAT_RE,
0
     :if => proc{|record| !record.bugtracker_url.blank? },
0
     :message => "Must begin with http(s)"
0
-
0
+
0
   before_validation :downcase_slug
0
   after_create :create_mainline_repository
0
-
0
+
0
   LICENSES = [
0
     'Academic Free License v3.0',
0
     'MIT License',
0
@@ -68,47 +68,59 @@ class Project < ActiveRecord::Base
0
     'Other/Proprietary License',
0
     'None',
0
   ]
0
-
0
+
0
   def self.find_by_slug!(slug, opts = {})
0
     find_by_slug(slug, opts) || raise(ActiveRecord::RecordNotFound)
0
   end
0
-
0
+
0
   def self.per_page() 20 end
0
-
0
+
0
   def self.top_tags(limit = 10)
0
     tag_counts(:limit => limit, :order => "count desc")
0
   end
0
-
0
+
0
   def to_param
0
     slug
0
   end
0
-
0
+
0
   def admin?(candidate)
0
     candidate == user
0
   end
0
-
0
+
0
   def can_be_deleted_by?(candidate)
0
     (candidate == user) && (repositories.size == 1)
0
   end
0
-
0
+
0
   def tag_list=(tag_list)
0
     tag_list.gsub!(",", "")
0
-
0
+
0
     super
0
   end
0
-
0
+
0
+ def home_url=(url)
0
+ self[:home_url] = clean_url(url)
0
+ end
0
+
0
+ def mailinglist_url=(url)
0
+ self[:mailinglist_url] = clean_url(url)
0
+ end
0
+
0
+ def bugtracker_url=(url)
0
+ self[:bugtracker_url] = clean_url(url)
0
+ end
0
+
0
   def stripped_description
0
     description.gsub(/<\/?[^>]*>/, "")
0
     # sanitizer = HTML::WhiteListSanitizer.new
0
     # sanitizer.sanitize(description, :tags => %w(str), :attributes => %w(class))
0
   end
0
-
0
+
0
   def to_xml(opts = {})
0
     info = Proc.new { |options|
0
       builder = options[:builder]
0
       builder.owner user.login
0
-
0
- builder.repositories :type => "array" do
0
+
0
+ builder.repositories :type => "array" do
0
         repositories.each { |repo|
0
           builder.repository do
0
             builder.id repo.id
0
@@ -120,14 +132,22 @@ class Project < ActiveRecord::Base
0
     }
0
     super({:procs => [info]}.merge(opts))
0
   end
0
-
0
+
0
   protected
0
     def create_mainline_repository
0
       self.repositories.create!(:user => self.user, :name => "mainline")
0
     end
0
-
0
+
0
     def downcase_slug
0
       slug.downcase! if slug
0
     end
0
-
0
+
0
+ # Try our best to guess the url
0
+ def clean_url(url)
0
+ begin
0
+ url = "http://#{url}" if URI.parse(url).class == URI::Generic
0
+ rescue
0
+ end
0
+ url
0
+ end
0
 end
...
1
2
3
4
 
5
6
7
8
 
 
9
10
11
12
 
13
14
15
16
 
17
18
19
20
21
22
23
 
24
25
26
27
28
 
29
30
31
...
33
34
35
36
 
37
38
39
40
41
42
 
43
44
45
46
47
48
 
49
50
51
...
54
55
56
57
 
58
59
60
61
62
63
64
 
 
65
66
67
68
 
69
70
71
72
73
74
 
75
76
77
...
79
80
81
82
 
83
84
85
86
87
 
88
89
90
91
92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
...
1
2
3
 
4
5
6
 
 
7
8
9
10
11
 
12
13
14
15
 
16
17
18
19
20
21
22
 
23
24
25
26
27
 
28
29
30
31
...
33
34
35
 
36
37
38
39
40
41
 
42
43
44
45
46
47
 
48
49
50
51
...
54
55
56
 
57
58
59
60
61
62
 
 
63
64
65
66
67
 
68
69
70
71
72
73
 
74
75
76
77
...
79
80
81
 
82
83
84
85
86
 
87
88
89
90
91
 
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
0
@@ -1,31 +1,31 @@
0
 require File.dirname(__FILE__) + '/../spec_helper'
0
 
0
 describe Project do
0
-
0
+
0
   def create_project(options={})
0
     Project.new({
0
- :title => "foo project",
0
- :slug => "foo",
0
+ :title => "foo project",
0
+ :slug => "foo",
0
       :user => users(:johan)
0
     }.merge(options))
0
   end
0
-
0
+
0
   it "should have valid associations" do
0
     create_project.should have_valid_associations
0
   end
0
-
0
+
0
   it "should have a title to be valid" do
0
     project = create_project(:title => nil)
0
     project.should_not be_valid
0
     project.title = "foo"
0
     project.should be_valid
0
   end
0
-
0
+
0
   it "should have a slug to be valid" do
0
     project = create_project(:slug => nil)
0
     project.should_not be_valid
0
   end
0
-
0
+
0
   it "should have a unique slug to be valid" do
0
     p1 = create_project
0
     p1.save!
0
@@ -33,19 +33,19 @@ describe Project do
0
     p2.should_not be_valid
0
     p2.should have(1).error_on(:slug)
0
   end
0
-
0
+
0
   it "should have an alphanumeric slug" do
0
     project = create_project(:slug => "asd asd")
0
     project.valid?
0
     project.should_not be_valid
0
   end
0
-
0
+
0
   it "should downcase the slug before validation" do
0
     project = create_project(:slug => "FOO")
0
     project.valid?
0
     project.slug.should == "foo"
0
   end
0
-
0
+
0
   it "creates an initial repository for itself" do
0
     project = create_project
0
     project.save
0
@@ -54,24 +54,24 @@ describe Project do
0
     project.repositories.first.user.should == project.user
0
     project.user.can_write_to?(project.repositories.first).should == true
0
   end
0
-
0
+
0
   it "finds a project by slug or raises" do
0
     Project.find_by_slug!(projects(:johans).slug).should == projects(:johans)
0
     proc{
0
       Project.find_by_slug!("asdasdasd")
0
     }.should raise_error(ActiveRecord::RecordNotFound)
0
- end
0
-
0
+ end
0
+
0
   it "has the slug as its params" do
0
     projects(:johans).to_param.should == projects(:johans).slug
0
   end
0
-
0
+
0
   it "knows if a user is a admin on a project" do
0
     projects(:johans).admin?(users(:johan)).should == true
0
     projects(:johans).admin?(users(:moe)).should == false
0
     projects(:johans).admin?(:false).should == false
0
   end
0
-
0
+
0
   it "knows if a user can delete the project" do
0
     project = projects(:johans)
0
     project.can_be_deleted_by?(users(:moe)).should == false
0
@@ -79,15 +79,29 @@ describe Project do
0
     project.repositories.last.destroy
0
     project.reload.can_be_deleted_by?(users(:johan)).should == true
0
   end
0
-
0
+
0
   it "should strip html tags" do
0
     project = create_project(:description => "<h1>Project A</h1>\n<b>Project A</b> is a....")
0
     project.stripped_description.should == "Project A\nProject A is a...."
0
   end
0
-
0
+
0
   # it "should strip html tags, except highlights" do
0
   # project = create_project(:description => %Q{<h1>Project A</h1>\n<strong class="highlight">Project A</strong> is a....})
0
   # project.stripped_description.should == %Q(Project A\n<strong class="highlight">Project A</strong> is a....)
0
   # end
0
-
0
+
0
+ it "should have valid urls ( prepending http:// if needed )" do
0
+ project = projects(:johans)
0
+ [ :home_url, :mailinglist_url, :bugtracker_url ].each do |attr|
0
+ project.should be_valid
0
+ project.send("#{attr}=", 'http://blah.com')
0
+ project.should be_valid
0
+ project.send("#{attr}=", 'ftp://blah.com')
0
+ project.should_not be_valid
0
+ project.send("#{attr}=", 'blah.com')
0
+ project.should be_valid
0
+ project.send(attr).should == 'http://blah.com'
0
+ end
0
+ end
0
+
0
 end

Comments

    No one has commented yet.