foca-integrity 0.1.9.1 → 0.1.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. data/.gitignore +12 -0
  2. data/CHANGES +28 -0
  3. data/README.markdown +6 -0
  4. data/Rakefile +44 -83
  5. data/config/heroku/.gems +0 -3
  6. data/config/heroku/integrity-config.rb +4 -1
  7. data/integrity.gemspec +18 -6
  8. data/lib/integrity.rb +9 -5
  9. data/lib/integrity/app.rb +8 -8
  10. data/lib/integrity/build.rb +14 -7
  11. data/lib/integrity/commit.rb +0 -8
  12. data/lib/integrity/helpers/authorization.rb +1 -1
  13. data/lib/integrity/helpers/breadcrumbs.rb +1 -1
  14. data/lib/integrity/helpers/rendering.rb +8 -2
  15. data/lib/integrity/helpers/urls.rb +33 -23
  16. data/lib/integrity/installer.rb +18 -17
  17. data/lib/integrity/notifier/base.rb +12 -3
  18. data/lib/integrity/project.rb +6 -6
  19. data/lib/integrity/project_builder.rb +35 -35
  20. data/test/acceptance/api_test.rb +1 -1
  21. data/test/acceptance/browse_project_builds_test.rb +1 -1
  22. data/test/acceptance/browse_project_test.rb +1 -1
  23. data/test/acceptance/build_notifications_test.rb +1 -1
  24. data/test/acceptance/create_project_test.rb +1 -1
  25. data/test/acceptance/delete_project_test.rb +1 -1
  26. data/test/acceptance/edit_project_test.rb +1 -1
  27. data/test/acceptance/error_page_test.rb +1 -1
  28. data/test/acceptance/installer_test.rb +2 -6
  29. data/test/acceptance/manual_build_project_test.rb +1 -1
  30. data/test/acceptance/not_found_page_test.rb +29 -0
  31. data/test/acceptance/notifier_test.rb +1 -1
  32. data/test/acceptance/project_syndication_test.rb +1 -1
  33. data/test/acceptance/stylesheet_test.rb +10 -2
  34. data/test/acceptance/unauthorized_page_test.rb +20 -0
  35. data/test/helpers.rb +20 -7
  36. data/test/helpers/acceptance.rb +1 -0
  37. data/test/unit/build_test.rb +33 -0
  38. data/test/unit/commit_test.rb +0 -21
  39. data/test/unit/helpers_test.rb +67 -20
  40. data/test/unit/integrity_test.rb +23 -6
  41. data/test/unit/migrations_test.rb +2 -2
  42. data/test/unit/notifier_test.rb +5 -0
  43. data/test/unit/project_builder_test.rb +8 -1
  44. data/test/unit/project_test.rb +7 -0
  45. data/views/home.haml +2 -2
  46. data/views/layout.haml +6 -5
  47. data/views/new.haml +1 -1
  48. data/views/not_found.haml +2 -2
  49. data/views/unauthorized.haml +4 -4
  50. metadata +105 -6
  51. data/test/acceptance/helpers.rb +0 -2
  52. data/vendor/sinatra-ditties/README.rdoc +0 -3
  53. data/vendor/sinatra-ditties/lib/sinatra/ditties.rb +0 -12
  54. data/vendor/sinatra-ditties/lib/sinatra/ditties/authorization.rb +0 -61
  55. data/vendor/sinatra-ditties/lib/sinatra/ditties/mailer.rb +0 -146
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/helpers"
1
+ require File.dirname(__FILE__) + "/../helpers/acceptance"
2
2
 
3
3
  class NotifierConfigIssues < Test::Unit::AcceptanceTestCase
4
4
  story <<-EOS
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/helpers"
1
+ require File.dirname(__FILE__) + "/../helpers/acceptance"
2
2
 
3
3
  class ProjectSyndicationTest < Test::Unit::AcceptanceTestCase
4
4
  story <<-EOS
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + "/helpers"
1
+ require File.dirname(__FILE__) + "/../helpers/acceptance"
2
2
 
3
3
  class IntegrityStylesheetTest < Test::Unit::AcceptanceTestCase
4
4
  story <<-EOS
@@ -8,11 +8,19 @@ class IntegrityStylesheetTest < Test::Unit::AcceptanceTestCase
8
8
  EOS
9
9
 
10
10
  scenario "browsing on some Integrity install" do
11
+ visit "/"
12
+ assert_have_tag("link[@href='/integrity.css']")
11
13
  visit "/integrity.css"
12
14
 
13
15
  assert_contain("body {")
14
- # TODO: better test
16
+ # TODO: Check that it actually returns a 302
15
17
  assert_equal %Q{"2465c472aacf302259dde5146a841e45"},
16
18
  webrat_session.send(:response).headers["ETag"]
19
+
20
+ visit "/reset.css"
21
+ assert_contain("Yahoo!")
22
+
23
+ visit "/buttons.css"
24
+ assert_contain("button {")
17
25
  end
18
26
  end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) + "/../helpers/acceptance"
2
+
3
+ class UnauthorizedPageTest < Test::Unit::AcceptanceTestCase
4
+ story <<-EOS
5
+ As an administrator,
6
+ I want to be shown a friendly login error page
7
+ So that I don't feel guilty of loosing my password
8
+ EOS
9
+
10
+ scenario "an administrator (who's amnesiac) tries to login" do
11
+ project = Project.gen(:public => false)
12
+
13
+ visit "/#{project.name}/edit"
14
+ assert_equal 401, response_code
15
+
16
+ # TODO click_link "try again"
17
+ assert_have_tag("a[@href='/login']", :content => "try again")
18
+ assert_have_tag("a[@href='/']", :content => "go back")
19
+ end
20
+ end
@@ -1,5 +1,4 @@
1
- $:.unshift File.dirname(__FILE__) + "/../lib", File.dirname(__FILE__),
2
- File.dirname(__FILE__) + "/../vendor/webrat/lib"
1
+ $:.unshift File.dirname(__FILE__) + "/../lib", File.dirname(__FILE__)
3
2
 
4
3
  %w(test/unit
5
4
  context
@@ -9,19 +8,18 @@ storyteller
9
8
  webrat/sinatra
10
9
  rr
11
10
  mocha
12
- test/zentest_assertions
13
11
  dm-sweatshop).each { |dependency|
14
12
  begin
15
13
  require dependency
16
- rescue LoadError
14
+ rescue LoadError => e
17
15
  puts "You're missing some gems required to run the tests."
18
- puts "Please run `rake test:install_dependencies`"
19
- puts "You'll probably need to run that command as root or with sudo."
16
+ puts "Please run `rake test:setup`"
17
+ puts "NOTE: You'll probably need to run that command as root or with sudo."
20
18
 
21
19
  puts "Thanks :)"
22
20
  puts
23
21
 
24
- exit 1
22
+ raise
25
23
  end
26
24
  }
27
25
 
@@ -39,6 +37,21 @@ module TestHelper
39
37
  def ignore_logs!
40
38
  Integrity.config[:log] = "/tmp/integrity.test.log"
41
39
  end
40
+
41
+ def capture_stdout
42
+ output = StringIO.new
43
+ $stdout = output
44
+ yield
45
+ $stdout = STDOUT
46
+ output
47
+ end
48
+
49
+ def silence_warnings
50
+ $VERBOSE, v = nil, $VERBOSE
51
+ yield
52
+ ensure
53
+ $VERBOSE = v
54
+ end
42
55
  end
43
56
 
44
57
  class Test::Unit::TestCase
@@ -1,3 +1,4 @@
1
+ require File.dirname(__FILE__) + "/../helpers"
1
2
  require "helpers/acceptance/git_helper"
2
3
 
3
4
  module AcceptanceHelper
@@ -36,6 +36,18 @@ class BuildTest < Test::Unit::TestCase
36
36
  @build.successful = false
37
37
  @build.status.should be(:failed)
38
38
  end
39
+
40
+ test "deprecated properties" do
41
+ silence_warnings {
42
+ @build.short_commit_identifier.should == @build.commit.short_identifier
43
+ @build.commit_identifier.should == @build.commit.identifier
44
+ @build.commit_author.should == @build.commit.author
45
+ @build.commit_message.should == @build.commit.message
46
+ @build.commited_at.should == @build.commit.committed_at
47
+ @build.project_id.should == @build.commit.project_id
48
+ @build.should respond_to(:commit_metadata)
49
+ }
50
+ end
39
51
  end
40
52
 
41
53
  describe "Pending builds" do
@@ -48,4 +60,25 @@ class BuildTest < Test::Unit::TestCase
48
60
  Build.should have(3).pending
49
61
  end
50
62
  end
63
+
64
+ describe "Queueing a build" do
65
+ before(:each) do
66
+ @commit = Commit.gen
67
+ stub.instance_of(ProjectBuilder).build(@commit)
68
+ end
69
+
70
+ it "creates an empty Build" do
71
+ @commit.build.should be_nil
72
+ Build.queue(@commit)
73
+ @commit.build.should_not be_nil
74
+ end
75
+
76
+ it "ensures the build is saved" do
77
+ @commit.build.should be_nil
78
+ Build.queue(@commit)
79
+
80
+ commit = Commit.first(:identifier => @commit.identifier)
81
+ commit.build.should_not be_nil
82
+ end
83
+ end
51
84
  end
@@ -59,25 +59,4 @@ class CommitTest < Test::Unit::TestCase
59
59
  commit.human_readable_status.should be("658ba96 hasn't been built yet")
60
60
  end
61
61
  end
62
-
63
- describe "Queueing a build" do
64
- before(:each) do
65
- @commit = Commit.gen
66
- stub.instance_of(ProjectBuilder).build(@commit)
67
- end
68
-
69
- it "creates an empty Build" do
70
- @commit.build.should be_nil
71
- @commit.queue_build
72
- @commit.build.should_not be_nil
73
- end
74
-
75
- it "ensures the build is saved" do
76
- @commit.build.should be_nil
77
- @commit.queue_build
78
-
79
- commit = Commit.first(:identifier => @commit.identifier)
80
- commit.build.should_not be_nil
81
- end
82
- end
83
62
  end
@@ -1,25 +1,72 @@
1
1
  require File.dirname(__FILE__) + "/../helpers"
2
2
 
3
3
  class BrowsePublicProjectsTest < Test::Unit::TestCase
4
- include ::Integrity::Helpers
4
+ setup do
5
+ @h = Module.new { extend Integrity::Helpers }
6
+ end
5
7
 
6
8
  test "#pretty_date" do
7
- pretty_date(Time.now).should == "today"
8
- pretty_date(Time.new - 86400).should == "yesterday"
9
+ @h.pretty_date(Time.now).should == "today"
10
+ @h.pretty_date(Time.new - 86400).should == "yesterday"
9
11
 
10
- pretty_date(Time.mktime(1995, 12, 01)).should == "on Dec 01st"
11
- pretty_date(Time.mktime(1995, 12, 21)).should == "on Dec 21st"
12
- pretty_date(Time.mktime(1995, 12, 31)).should == "on Dec 31st"
12
+ @h.pretty_date(Time.mktime(1995, 12, 01)).should == "on Dec 01st"
13
+ @h.pretty_date(Time.mktime(1995, 12, 21)).should == "on Dec 21st"
14
+ @h.pretty_date(Time.mktime(1995, 12, 31)).should == "on Dec 31st"
13
15
 
14
- pretty_date(Time.mktime(1995, 12, 22)).should == "on Dec 22nd"
15
- pretty_date(Time.mktime(1995, 12, 22)).should == "on Dec 22nd"
16
+ @h.pretty_date(Time.mktime(1995, 12, 22)).should == "on Dec 22nd"
17
+ @h.pretty_date(Time.mktime(1995, 12, 22)).should == "on Dec 22nd"
16
18
 
17
- pretty_date(Time.mktime(1995, 12, 03)).should == "on Dec 03rd"
18
- pretty_date(Time.mktime(1995, 12, 23)).should == "on Dec 23rd"
19
+ @h.pretty_date(Time.mktime(1995, 12, 03)).should == "on Dec 03rd"
20
+ @h.pretty_date(Time.mktime(1995, 12, 23)).should == "on Dec 23rd"
19
21
 
20
- pretty_date(Time.mktime(1995, 12, 15)).should == "on Dec 15th"
21
- pretty_date(Time.mktime(1995, 12, 15)).should == "on Dec 15th"
22
- pretty_date(Time.mktime(1995, 12, 15)).should == "on Dec 15th"
22
+ @h.pretty_date(Time.mktime(1995, 12, 15)).should == "on Dec 15th"
23
+ @h.pretty_date(Time.mktime(1995, 12, 15)).should == "on Dec 15th"
24
+ @h.pretty_date(Time.mktime(1995, 12, 15)).should == "on Dec 15th"
25
+ end
26
+
27
+ describe "urls" do
28
+ before do
29
+ Integrity.config[:base_uri] = "http://example.org/ci"
30
+
31
+ @project = Project.gen(:name => "Foo Bar")
32
+ @build = Build.gen(:successful)
33
+ @commit = @build.commit
34
+ end
35
+
36
+ test "root" do
37
+ assert_equal "http://example.org/ci", @h.root_url.to_s
38
+ assert_equal "/ci", @h.root_path
39
+ assert_equal "/ci/stylesheet.css", @h.root_path("/stylesheet.css")
40
+
41
+ Integrity.config[:base_uri] = nil
42
+ @h.instance_variable_set(:@url, nil)
43
+ lambda { @h.root_url }.should raise_error
44
+
45
+ stub(@h).request { OpenStruct.new(:url => "http://0.0.0.0/") }
46
+ assert_equal "http://0.0.0.0/", @h.root_url.to_s
47
+ end
48
+
49
+ test "project" do
50
+ assert_equal "/ci/foo-bar", @h.project_path(@project)
51
+ assert_equal "http://example.org/ci/foo-bar",
52
+ @h.project_url(@project).to_s
53
+ end
54
+
55
+ test "commit" do
56
+ silence_warnings {
57
+ assert_equal "/ci/foo-bar/commits/#{@commit.identifier}",
58
+ @h.commit_path(@build.commit)
59
+ assert_equal "http://example.org/ci/foo-bar/commits/#{@commit.identifier}",
60
+ @h.commit_url(@build.commit).to_s
61
+ }
62
+ end
63
+
64
+ test "compat" do
65
+ silence_warnings {
66
+ assert_equal @h.build_path(@build), @h.commit_path(@build.commit)
67
+ assert_equal @h.build_url(@build), @h.commit_url(@build.commit)
68
+ }
69
+ end
23
70
  end
24
71
 
25
72
  describe "#push_url_for" do
@@ -27,30 +74,30 @@ class BrowsePublicProjectsTest < Test::Unit::TestCase
27
74
  @project = Project.gen(:integrity)
28
75
  Integrity.config[:admin_username] = "admin"
29
76
  Integrity.config[:admin_password] = "test"
30
-
31
- stub(self).request {
32
- OpenStruct.new(:url => "http://integrity.example.org:1234")
33
- }
77
+ Integrity.config[:base_uri] = "http://integrity.example.org:1234"
34
78
  end
35
79
 
36
80
  test "with auth disabled" do
37
81
  Integrity.config[:use_basic_auth] = false
38
82
 
39
- push_url_for(@project).should == "http://integrity.example.org:1234/integrity/push"
83
+ assert_equal "http://integrity.example.org:1234/integrity/push",
84
+ @h.push_url_for(@project)
40
85
  end
41
86
 
42
87
  test "with auth and hashing enabled" do
43
88
  Integrity.config[:use_basic_auth] = true
44
89
  Integrity.config[:hash_admin_password] = true
45
90
 
46
- push_url_for(@project).should == "http://admin:<password>@integrity.example.org:1234/integrity/push"
91
+ assert_equal "http://admin:<password>@integrity.example.org:1234/integrity/push",
92
+ @h.push_url_for(@project)
47
93
  end
48
94
 
49
95
  test "with auth enabled and hashing disabled" do
50
96
  Integrity.config[:use_basic_auth] = true
51
97
  Integrity.config[:hash_admin_password] = false
52
98
 
53
- push_url_for(@project).should == "http://admin:test@integrity.example.org:1234/integrity/push"
99
+ assert_equal "http://admin:test@integrity.example.org:1234/integrity/push",
100
+ @h.push_url_for(@project)
54
101
  end
55
102
  end
56
103
  end
@@ -1,14 +1,31 @@
1
1
  require File.dirname(__FILE__) + "/../helpers"
2
2
 
3
3
  class IntegrityTest < Test::Unit::TestCase
4
- test "Integrity.new loads configuration from a file" do
5
- stub(DataMapper).setup { nil }
4
+ describe "#new" do
5
+ setup do
6
+ stub(DataMapper).setup { nil }
7
+ @config_file = File.dirname(__FILE__) + "/../../config/config.sample.yml"
8
+ end
6
9
 
7
- file = File.dirname(__FILE__) + "/../../config/config.sample.yml"
8
- Integrity.new(file)
10
+ it "doesn't require any argument" do
11
+ Integrity.new
9
12
 
10
- Integrity.config[:base_uri].should == "http://integrity.domain.tld"
11
- Integrity.config[:export_directory].should == "/path/to/scm/exports"
13
+ assert_equal Integrity.default_configuration[:log],
14
+ Integrity.config[:log]
15
+ end
16
+
17
+ it "loads configuration from a file" do
18
+ Integrity.new(@config_file)
19
+
20
+ assert_equal "http://integrity.domain.tld", Integrity.config[:base_uri]
21
+ assert_equal "/path/to/scm/exports", Integrity.config[:export_directory]
22
+ end
23
+
24
+ it "takes configuration as an hash" do
25
+ Integrity.new(:base_uri => "http://foo.org")
26
+
27
+ assert_equal "http://foo.org", Integrity.config[:base_uri]
28
+ end
12
29
  end
13
30
 
14
31
  specify "config is just a hash" do
@@ -28,7 +28,7 @@ class MigrationsTest < Test::Unit::TestCase
28
28
  end
29
29
 
30
30
  test "upgrading a pre migration database" do
31
- util_capture { Integrity.migrate_db }
31
+ capture_stdout { Integrity.migrate_db }
32
32
 
33
33
  current_migrations.should == ["initial", "add_commits"]
34
34
  assert table_exists?("integrity_projects")
@@ -40,7 +40,7 @@ class MigrationsTest < Test::Unit::TestCase
40
40
  test "migrating data from initial to add_commits migration" do
41
41
  load_initial_migration_fixture
42
42
 
43
- util_capture { Integrity.migrate_db }
43
+ capture_stdout { Integrity.migrate_db }
44
44
  current_migrations.should == ["initial", "add_commits"]
45
45
 
46
46
  sinatra = Project.first(:name => "Sinatra")
@@ -1,6 +1,11 @@
1
1
  require File.dirname(__FILE__) + "/../helpers"
2
2
 
3
3
  class NotifierTest < Test::Unit::TestCase
4
+ test "deprecated methods" do
5
+ Notifier::Base.new(Build.gen, {}).should respond_to(:build)
6
+ Notifier::Base.new(Build.gen, {}).should respond_to(:build_url)
7
+ end
8
+
4
9
  specify "IRC fixture is valid and can be saved" do
5
10
  lambda do
6
11
  Notifier.generate(:irc).tap do |project|
@@ -52,7 +52,6 @@ class ProjectBuilderTest < Test::Unit::TestCase
52
52
  }.should raise_error
53
53
  end
54
54
 
55
-
56
55
  it "sets the build status to failure when the build command exits with a non-zero status" do
57
56
  @project.update_attributes(:command => "exit 1")
58
57
  SCM::Git.any_instance.expects(:with_revision).with(@commit.identifier).yields
@@ -94,6 +93,14 @@ class ProjectBuilderTest < Test::Unit::TestCase
94
93
  @project.update_attributes(:uri => "scm://example.org")
95
94
  lambda { ProjectBuilder.new(@project) }.should raise_error(SCM::SCMUnknownError)
96
95
  end
96
+
97
+ it "doesn't fail if the commit identifier can't be retrieved" do
98
+ SCM::Git.any_instance.expects(:with_revision).with(@commit.identifier).yields
99
+ SCM::Git.any_instance.expects(:info).returns(false)
100
+ lambda {
101
+ ProjectBuilder.new(@project).build(@commit)
102
+ }.should_not raise_error
103
+ end
97
104
  end
98
105
 
99
106
  describe "When deleting the code from disk" do
@@ -110,6 +110,13 @@ class ProjectTest < Test::Unit::TestCase
110
110
  project = Project.gen(:commits => commits)
111
111
  project.last_commit.should == commits.sort_by {|c| c.committed_at }.last
112
112
  end
113
+
114
+ test "deprecated properties" do
115
+ silence_warnings {
116
+ @project.last_build.should == @project.last_commit
117
+ @project.previous_builds.should == @project.previous_commits
118
+ }
119
+ end
113
120
  end
114
121
 
115
122
  describe "Validation" do
@@ -4,7 +4,7 @@
4
4
  %h1
5
5
  Why don't you
6
6
  = succeed "?" do
7
- %a{ :href => "/new" } create your first project
7
+ %a{ :href => root_path("/new") } create your first project
8
8
  - else
9
9
  %ul#projects
10
10
  - @projects.each do |project|
@@ -18,4 +18,4 @@
18
18
  - else
19
19
  = project.human_readable_status
20
20
  %p#new
21
- %a{ :href => "/new" } Add a new project
21
+ %a{ :href => root_path("/new") } Add a new project
@@ -4,11 +4,12 @@
4
4
  %meta{ :content => "text/html; charset=utf-8", :"http-equiv" => "Content-Type" }
5
5
  %meta{ :content => "en", :"http-equiv" => "Content-Language" }
6
6
  %title= "#{@title.last} | integrity"
7
- %link{ :media => "screen", :type => "text/css", :href => "/reset.css", :rel => "stylesheet" }
8
- %link{ :media => "screen", :type => "text/css", :href => "/buttons.css", :rel => "stylesheet" }
9
- %link{ :media => "screen", :type => "text/css", :href => "/integrity.css", :rel => "stylesheet" }
7
+ - stylesheets(:reset, :buttons, :integrity)
10
8
  - unless @project.nil?
11
- %link{ :rel => "alternate", :type => "application/atom+xml", :title => "Build history Atom", :href => "#{project_path(@project)}.atom"}
9
+ %link{ :rel => "alternate", |
10
+ :type => "application/atom+xml", |
11
+ :title => "Build history Atom", |
12
+ :href => "#{project_path(@project)}.atom"} |
12
13
 
13
14
  %body
14
15
  #header
@@ -24,5 +25,5 @@
24
25
  %strong&= current_user
25
26
  - else
26
27
  Hey there!
27
- %a{ :href => "/login" } Log In
28
+ %a{ :href => root_path("/login") } Log In
28
29
  if you have a user