integrity 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (249) hide show
  1. data/README.markdown +7 -0
  2. data/Rakefile +59 -132
  3. data/VERSION.yml +1 -1
  4. data/config/config.ru +29 -0
  5. data/config/config.sample.ru +6 -16
  6. data/config/config.sample.yml +15 -12
  7. data/config/config.yml +34 -0
  8. data/lib/integrity.rb +13 -13
  9. data/lib/integrity/app.rb +138 -0
  10. data/lib/integrity/author.rb +39 -0
  11. data/lib/integrity/build.rb +54 -31
  12. data/lib/integrity/commit.rb +71 -0
  13. data/lib/integrity/helpers.rb +3 -3
  14. data/lib/integrity/helpers/authorization.rb +2 -2
  15. data/lib/integrity/helpers/forms.rb +3 -3
  16. data/lib/integrity/helpers/pretty_output.rb +1 -1
  17. data/lib/integrity/helpers/rendering.rb +6 -1
  18. data/lib/integrity/helpers/resources.rb +9 -3
  19. data/lib/integrity/helpers/urls.rb +15 -13
  20. data/lib/integrity/installer.rb +45 -56
  21. data/lib/integrity/migrations.rb +31 -48
  22. data/lib/integrity/notifier.rb +14 -16
  23. data/lib/integrity/notifier/base.rb +29 -19
  24. data/lib/integrity/notifier/test_helpers.rb +100 -0
  25. data/lib/integrity/project.rb +69 -33
  26. data/lib/integrity/project_builder.rb +23 -14
  27. data/lib/integrity/scm/git.rb +15 -14
  28. data/lib/integrity/scm/git/uri.rb +9 -9
  29. data/test/acceptance/api_test.rb +97 -0
  30. data/test/acceptance/browse_project_builds_test.rb +65 -0
  31. data/test/acceptance/browse_project_test.rb +95 -0
  32. data/test/acceptance/build_notifications_test.rb +42 -0
  33. data/test/acceptance/create_project_test.rb +97 -0
  34. data/test/acceptance/delete_project_test.rb +53 -0
  35. data/test/acceptance/edit_project_test.rb +117 -0
  36. data/test/acceptance/error_page_test.rb +18 -0
  37. data/test/acceptance/helpers.rb +2 -0
  38. data/test/acceptance/installer_test.rb +62 -0
  39. data/test/acceptance/manual_build_project_test.rb +82 -0
  40. data/test/acceptance/notifier_test.rb +109 -0
  41. data/test/acceptance/project_syndication_test.rb +30 -0
  42. data/test/acceptance/stylesheet_test.rb +18 -0
  43. data/test/helpers.rb +59 -26
  44. data/test/helpers/acceptance.rb +19 -65
  45. data/test/helpers/acceptance/email_notifier.rb +55 -0
  46. data/test/helpers/acceptance/git_helper.rb +15 -15
  47. data/test/helpers/acceptance/textfile_notifier.rb +3 -3
  48. data/test/helpers/expectations.rb +0 -1
  49. data/test/helpers/expectations/be_a.rb +4 -4
  50. data/test/helpers/expectations/change.rb +5 -5
  51. data/test/helpers/expectations/have.rb +4 -4
  52. data/test/helpers/expectations/predicates.rb +4 -4
  53. data/test/helpers/fixtures.rb +44 -18
  54. data/test/helpers/initial_migration_fixture.sql +44 -0
  55. data/test/unit/build_test.rb +51 -0
  56. data/test/unit/commit_test.rb +83 -0
  57. data/test/unit/helpers_test.rb +56 -0
  58. data/test/unit/integrity_test.rb +18 -0
  59. data/test/unit/migrations_test.rb +56 -0
  60. data/test/unit/notifier_test.rb +123 -0
  61. data/test/unit/project_builder_test.rb +108 -0
  62. data/test/unit/project_test.rb +282 -0
  63. data/test/unit/scm_test.rb +54 -0
  64. data/vendor/webrat/History.txt +306 -0
  65. data/vendor/webrat/MIT-LICENSE.txt +19 -0
  66. data/vendor/webrat/README.rdoc +85 -0
  67. data/vendor/webrat/Rakefile +151 -0
  68. data/vendor/webrat/install.rb +1 -0
  69. data/vendor/webrat/lib/webrat.rb +34 -0
  70. data/vendor/webrat/lib/webrat/core.rb +14 -0
  71. data/vendor/webrat/lib/webrat/core/configuration.rb +98 -0
  72. data/vendor/webrat/lib/webrat/core/elements/area.rb +31 -0
  73. data/vendor/webrat/lib/webrat/core/elements/element.rb +33 -0
  74. data/vendor/webrat/lib/webrat/core/elements/field.rb +403 -0
  75. data/vendor/webrat/lib/webrat/core/elements/form.rb +103 -0
  76. data/vendor/webrat/lib/webrat/core/elements/label.rb +31 -0
  77. data/vendor/webrat/lib/webrat/core/elements/link.rb +90 -0
  78. data/vendor/webrat/lib/webrat/core/elements/select_option.rb +35 -0
  79. data/vendor/webrat/lib/webrat/core/locators.rb +20 -0
  80. data/vendor/webrat/lib/webrat/core/locators/area_locator.rb +38 -0
  81. data/vendor/webrat/lib/webrat/core/locators/button_locator.rb +54 -0
  82. data/vendor/webrat/lib/webrat/core/locators/field_by_id_locator.rb +37 -0
  83. data/vendor/webrat/lib/webrat/core/locators/field_labeled_locator.rb +56 -0
  84. data/vendor/webrat/lib/webrat/core/locators/field_locator.rb +25 -0
  85. data/vendor/webrat/lib/webrat/core/locators/field_named_locator.rb +41 -0
  86. data/vendor/webrat/lib/webrat/core/locators/form_locator.rb +19 -0
  87. data/vendor/webrat/lib/webrat/core/locators/label_locator.rb +34 -0
  88. data/vendor/webrat/lib/webrat/core/locators/link_locator.rb +66 -0
  89. data/vendor/webrat/lib/webrat/core/locators/locator.rb +20 -0
  90. data/vendor/webrat/lib/webrat/core/locators/select_option_locator.rb +59 -0
  91. data/vendor/webrat/lib/webrat/core/logging.rb +21 -0
  92. data/vendor/webrat/lib/webrat/core/matchers.rb +4 -0
  93. data/vendor/webrat/lib/webrat/core/matchers/have_content.rb +73 -0
  94. data/vendor/webrat/lib/webrat/core/matchers/have_selector.rb +74 -0
  95. data/vendor/webrat/lib/webrat/core/matchers/have_tag.rb +21 -0
  96. data/vendor/webrat/lib/webrat/core/matchers/have_xpath.rb +147 -0
  97. data/vendor/webrat/lib/webrat/core/methods.rb +61 -0
  98. data/vendor/webrat/lib/webrat/core/mime.rb +29 -0
  99. data/vendor/webrat/lib/webrat/core/save_and_open_page.rb +50 -0
  100. data/vendor/webrat/lib/webrat/core/scope.rb +350 -0
  101. data/vendor/webrat/lib/webrat/core/session.rb +281 -0
  102. data/vendor/webrat/lib/webrat/core/xml.rb +115 -0
  103. data/vendor/webrat/lib/webrat/core/xml/hpricot.rb +19 -0
  104. data/vendor/webrat/lib/webrat/core/xml/nokogiri.rb +76 -0
  105. data/vendor/webrat/lib/webrat/core/xml/rexml.rb +24 -0
  106. data/vendor/webrat/lib/webrat/core_extensions/blank.rb +58 -0
  107. data/vendor/webrat/lib/webrat/core_extensions/deprecate.rb +8 -0
  108. data/vendor/webrat/lib/webrat/core_extensions/detect_mapped.rb +12 -0
  109. data/vendor/webrat/lib/webrat/core_extensions/meta_class.rb +6 -0
  110. data/vendor/webrat/lib/webrat/core_extensions/nil_to_param.rb +5 -0
  111. data/vendor/webrat/lib/webrat/mechanize.rb +74 -0
  112. data/vendor/webrat/lib/webrat/merb.rb +9 -0
  113. data/vendor/webrat/lib/webrat/merb_session.rb +65 -0
  114. data/vendor/webrat/lib/webrat/rack.rb +24 -0
  115. data/vendor/webrat/lib/webrat/rails.rb +105 -0
  116. data/vendor/webrat/lib/webrat/rspec-rails.rb +13 -0
  117. data/vendor/webrat/lib/webrat/selenium.rb +154 -0
  118. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/button.js +12 -0
  119. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/label.js +16 -0
  120. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webrat.js +5 -0
  121. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webratlink.js +9 -0
  122. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js +15 -0
  123. data/vendor/webrat/lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js +5 -0
  124. data/vendor/webrat/lib/webrat/selenium/matchers.rb +4 -0
  125. data/vendor/webrat/lib/webrat/selenium/matchers/have_content.rb +66 -0
  126. data/vendor/webrat/lib/webrat/selenium/matchers/have_selector.rb +49 -0
  127. data/vendor/webrat/lib/webrat/selenium/matchers/have_tag.rb +72 -0
  128. data/vendor/webrat/lib/webrat/selenium/matchers/have_xpath.rb +45 -0
  129. data/vendor/webrat/lib/webrat/selenium/selenium_extensions.js +6 -0
  130. data/vendor/webrat/lib/webrat/selenium/selenium_session.rb +247 -0
  131. data/vendor/webrat/lib/webrat/sinatra.rb +44 -0
  132. data/vendor/webrat/spec/fakes/test_session.rb +34 -0
  133. data/vendor/webrat/spec/integration/merb/Rakefile +35 -0
  134. data/vendor/webrat/spec/integration/merb/app/controllers/application.rb +2 -0
  135. data/vendor/webrat/spec/integration/merb/app/controllers/exceptions.rb +13 -0
  136. data/vendor/webrat/spec/integration/merb/app/controllers/testing.rb +18 -0
  137. data/vendor/webrat/spec/integration/merb/app/views/exceptions/not_acceptable.html.erb +63 -0
  138. data/vendor/webrat/spec/integration/merb/app/views/exceptions/not_found.html.erb +47 -0
  139. data/vendor/webrat/spec/integration/merb/app/views/layout/application.html.erb +12 -0
  140. data/vendor/webrat/spec/integration/merb/app/views/testing/show_form.html.erb +27 -0
  141. data/vendor/webrat/spec/integration/merb/config/environments/development.rb +15 -0
  142. data/vendor/webrat/spec/integration/merb/config/environments/rake.rb +11 -0
  143. data/vendor/webrat/spec/integration/merb/config/environments/test.rb +14 -0
  144. data/vendor/webrat/spec/integration/merb/config/init.rb +25 -0
  145. data/vendor/webrat/spec/integration/merb/config/rack.rb +11 -0
  146. data/vendor/webrat/spec/integration/merb/config/router.rb +33 -0
  147. data/vendor/webrat/spec/integration/merb/spec/spec.opts +1 -0
  148. data/vendor/webrat/spec/integration/merb/spec/spec_helper.rb +24 -0
  149. data/vendor/webrat/spec/integration/merb/spec/webrat_spec.rb +32 -0
  150. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/app_script.rb +31 -0
  151. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/common.rb +64 -0
  152. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/gem_ext.rb +124 -0
  153. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/main.thor +150 -0
  154. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/ops.rb +93 -0
  155. data/vendor/webrat/spec/integration/merb/tasks/merb.thor/utils.rb +40 -0
  156. data/vendor/webrat/spec/integration/rails/Rakefile +30 -0
  157. data/vendor/webrat/spec/integration/rails/app/controllers/application.rb +15 -0
  158. data/vendor/webrat/spec/integration/rails/app/controllers/webrat_controller.rb +39 -0
  159. data/vendor/webrat/spec/integration/rails/app/views/webrat/before_redirect_form.html.erb +4 -0
  160. data/vendor/webrat/spec/integration/rails/app/views/webrat/form.html.erb +28 -0
  161. data/vendor/webrat/spec/integration/rails/config/boot.rb +109 -0
  162. data/vendor/webrat/spec/integration/rails/config/environment.rb +12 -0
  163. data/vendor/webrat/spec/integration/rails/config/environments/development.rb +17 -0
  164. data/vendor/webrat/spec/integration/rails/config/environments/selenium.rb +22 -0
  165. data/vendor/webrat/spec/integration/rails/config/environments/test.rb +22 -0
  166. data/vendor/webrat/spec/integration/rails/config/initializers/inflections.rb +10 -0
  167. data/vendor/webrat/spec/integration/rails/config/initializers/mime_types.rb +5 -0
  168. data/vendor/webrat/spec/integration/rails/config/initializers/new_rails_defaults.rb +17 -0
  169. data/vendor/webrat/spec/integration/rails/config/locales/en.yml +5 -0
  170. data/vendor/webrat/spec/integration/rails/config/routes.rb +14 -0
  171. data/vendor/webrat/spec/integration/rails/public/404.html +30 -0
  172. data/vendor/webrat/spec/integration/rails/public/422.html +30 -0
  173. data/vendor/webrat/spec/integration/rails/public/500.html +33 -0
  174. data/vendor/webrat/spec/integration/rails/script/about +4 -0
  175. data/vendor/webrat/spec/integration/rails/script/console +3 -0
  176. data/vendor/webrat/spec/integration/rails/script/dbconsole +3 -0
  177. data/vendor/webrat/spec/integration/rails/script/destroy +3 -0
  178. data/vendor/webrat/spec/integration/rails/script/generate +3 -0
  179. data/vendor/webrat/spec/integration/rails/script/performance/benchmarker +3 -0
  180. data/vendor/webrat/spec/integration/rails/script/performance/profiler +3 -0
  181. data/vendor/webrat/spec/integration/rails/script/performance/request +3 -0
  182. data/vendor/webrat/spec/integration/rails/script/plugin +3 -0
  183. data/vendor/webrat/spec/integration/rails/script/process/inspector +3 -0
  184. data/vendor/webrat/spec/integration/rails/script/process/reaper +3 -0
  185. data/vendor/webrat/spec/integration/rails/script/process/spawner +3 -0
  186. data/vendor/webrat/spec/integration/rails/script/runner +3 -0
  187. data/vendor/webrat/spec/integration/rails/script/server +3 -0
  188. data/vendor/webrat/spec/integration/rails/test/integration/webrat_test.rb +80 -0
  189. data/vendor/webrat/spec/integration/rails/test/test_helper.rb +25 -0
  190. data/vendor/webrat/spec/integration/sinatra/Rakefile +5 -0
  191. data/vendor/webrat/spec/integration/sinatra/classic_app.rb +64 -0
  192. data/vendor/webrat/spec/integration/sinatra/modular_app.rb +16 -0
  193. data/vendor/webrat/spec/integration/sinatra/test/classic_app_test.rb +37 -0
  194. data/vendor/webrat/spec/integration/sinatra/test/modular_app_test.rb +18 -0
  195. data/vendor/webrat/spec/integration/sinatra/test/test_helper.rb +16 -0
  196. data/vendor/webrat/spec/private/core/configuration_spec.rb +104 -0
  197. data/vendor/webrat/spec/private/core/field_spec.rb +67 -0
  198. data/vendor/webrat/spec/private/core/link_spec.rb +24 -0
  199. data/vendor/webrat/spec/private/core/logging_spec.rb +10 -0
  200. data/vendor/webrat/spec/private/core/session_spec.rb +198 -0
  201. data/vendor/webrat/spec/private/mechanize/mechanize_session_spec.rb +81 -0
  202. data/vendor/webrat/spec/private/merb/merb_session_spec.rb +42 -0
  203. data/vendor/webrat/spec/private/nokogiri_spec.rb +77 -0
  204. data/vendor/webrat/spec/private/rails/attaches_file_spec.rb +81 -0
  205. data/vendor/webrat/spec/private/rails/rails_session_spec.rb +110 -0
  206. data/vendor/webrat/spec/private/selenium/selenium_session_spec.rb +44 -0
  207. data/vendor/webrat/spec/private/selenium/selenium_spec.rb +109 -0
  208. data/vendor/webrat/spec/public/basic_auth_spec.rb +24 -0
  209. data/vendor/webrat/spec/public/check_spec.rb +191 -0
  210. data/vendor/webrat/spec/public/choose_spec.rb +118 -0
  211. data/vendor/webrat/spec/public/click_area_spec.rb +106 -0
  212. data/vendor/webrat/spec/public/click_button_spec.rb +502 -0
  213. data/vendor/webrat/spec/public/click_link_spec.rb +469 -0
  214. data/vendor/webrat/spec/public/fill_in_spec.rb +209 -0
  215. data/vendor/webrat/spec/public/locators/field_by_xpath_spec.rb +19 -0
  216. data/vendor/webrat/spec/public/locators/field_labeled_spec.rb +157 -0
  217. data/vendor/webrat/spec/public/locators/field_with_id_spec.rb +16 -0
  218. data/vendor/webrat/spec/public/matchers/contain_spec.rb +114 -0
  219. data/vendor/webrat/spec/public/matchers/have_selector_spec.rb +135 -0
  220. data/vendor/webrat/spec/public/matchers/have_tag_spec.rb +39 -0
  221. data/vendor/webrat/spec/public/matchers/have_xpath_spec.rb +123 -0
  222. data/vendor/webrat/spec/public/reload_spec.rb +10 -0
  223. data/vendor/webrat/spec/public/save_and_open_spec.rb +51 -0
  224. data/vendor/webrat/spec/public/select_date_spec.rb +88 -0
  225. data/vendor/webrat/spec/public/select_datetime_spec.rb +106 -0
  226. data/vendor/webrat/spec/public/select_spec.rb +246 -0
  227. data/vendor/webrat/spec/public/select_time_spec.rb +79 -0
  228. data/vendor/webrat/spec/public/set_hidden_field_spec.rb +5 -0
  229. data/vendor/webrat/spec/public/submit_form_spec.rb +5 -0
  230. data/vendor/webrat/spec/public/visit_spec.rb +58 -0
  231. data/vendor/webrat/spec/public/within_spec.rb +177 -0
  232. data/vendor/webrat/spec/rcov.opts +1 -0
  233. data/vendor/webrat/spec/spec.opts +2 -0
  234. data/vendor/webrat/spec/spec_helper.rb +50 -0
  235. data/vendor/webrat/vendor/selenium-server.jar +0 -0
  236. data/views/_commit_info.haml +24 -0
  237. data/views/build.haml +2 -2
  238. data/views/error.haml +4 -3
  239. data/views/home.haml +3 -5
  240. data/views/integrity.sass +19 -6
  241. data/views/new.haml +6 -6
  242. data/views/project.builder +9 -9
  243. data/views/project.haml +14 -12
  244. metadata +319 -124
  245. data/app.rb +0 -138
  246. data/integrity.gemspec +0 -76
  247. data/lib/integrity/core_ext/string.rb +0 -5
  248. data/test/helpers/expectations/have_tag.rb +0 -128
  249. data/views/_build_info.haml +0 -18
@@ -2,15 +2,7 @@ module Integrity
2
2
  module Helpers
3
3
  module Urls
4
4
  def url(path)
5
- url = "#{request.scheme}://#{request.host}"
6
-
7
- if request.scheme == "https" && request.port != 443 ||
8
- request.scheme == "http" && request.port != 80
9
- url << ":#{request.port}"
10
- end
11
-
12
- url << "/" unless path.index("/").zero?
13
- url << path
5
+ Addressable::URI.parse(request.url).join(path).to_s
14
6
  end
15
7
 
16
8
  def root_url
@@ -35,13 +27,23 @@ module Integrity
35
27
  end.to_s
36
28
  end
37
29
 
38
- def build_path(build)
39
- "/#{build.project.permalink}/builds/#{build.commit_identifier}"
30
+ def commit_path(commit, *path)
31
+ project_path(commit.project, "commits", commit.identifier, *path)
32
+ end
33
+
34
+ def build_path(build, *path)
35
+ warn "#build_path is deprecated, use #commit_path instead"
36
+ commit_path build.commit, *path
37
+ end
38
+
39
+ def commit_url(commit)
40
+ url commit_path(commit)
40
41
  end
41
42
 
42
43
  def build_url(build)
43
- url build_path(build)
44
+ warn "#build_url is deprecated, use #commit_url instead"
45
+ commit_url build.commit
44
46
  end
45
47
  end
46
48
  end
47
- end
49
+ end
@@ -6,22 +6,48 @@ module Integrity
6
6
  include FileUtils
7
7
 
8
8
  desc "install [PATH]",
9
- "Copy template files to PATH. Next, go there and edit them."
9
+ "Copy template files to PATH for desired deployement strategy
10
+ (either Thin or Passenger). Next, go there and edit them."
11
+ method_options :passenger => false, :thin => false
10
12
  def install(path)
11
- @root = File.expand_path(path)
13
+ @root = Pathname(path).expand_path
12
14
 
13
15
  create_dir_structure
14
16
  copy_template_files
15
17
  edit_template_files
16
- create_db(root / "config.yml")
18
+ migrate_db(root.join("config.yml"))
17
19
  after_setup_message
18
20
  end
19
21
 
20
- desc "create_db [CONFIG]",
21
- "Checks the `database_uri` in CONFIG and creates and bootstraps a database for integrity"
22
- def create_db(config, direction="up")
22
+ desc "migrate_db [CONFIG]",
23
+ "Checks the `database_uri` in CONFIG and migrates the
24
+ database up to the lastest version."
25
+ def migrate_db(config)
23
26
  Integrity.new(config)
24
- migrate_db(direction, 1)
27
+
28
+ require "integrity/migrations"
29
+ Integrity.migrate_db
30
+ end
31
+
32
+ desc "launch [CONFIG]",
33
+ "Launch Integrity real quick."
34
+ method_options :config => :optional, :port => 4567
35
+ def launch
36
+ require "thin"
37
+ require "do_sqlite3"
38
+
39
+ if File.file?(options[:config].to_s)
40
+ Integrity.new(options[:config])
41
+ else
42
+ DataMapper.setup(:default, "sqlite3::memory:")
43
+ end
44
+
45
+ DataMapper.auto_migrate!
46
+
47
+ Thin::Server.start("0.0.0.0", options[:port], Integrity::App)
48
+ rescue LoadError => boom
49
+ missing_dependency = boom.message.split("--").last.lstrip
50
+ puts "Please install #{missing_dependency} to launch Integrity"
25
51
  end
26
52
 
27
53
  desc "version",
@@ -33,36 +59,26 @@ module Integrity
33
59
  private
34
60
  attr_reader :root
35
61
 
36
- def migrate_db(direction, level=nil)
37
- require "integrity/migrations"
38
-
39
- set_up_migrations unless migrations_already_set_up?
40
- add_initial_migration if tables_from_before_migrations_exist?
41
-
42
- case direction
43
- when "up" then Integrity::Migrations.migrate_up!(level)
44
- when "down" then Integrity::Migrations.migrate_down!(level)
45
- else raise ArgumentError, "DIRECTION must be either up or down"
46
- end
47
- end
48
-
49
62
  def create_dir_structure
50
63
  mkdir_p root
51
64
  mkdir_p root / "builds"
52
65
  mkdir_p root / "log"
53
- mkdir_p root / "public" # this one is to play nice with Passenger
54
- mkdir_p root / "tmp" # this one is to play nice with Passenger
66
+
67
+ if options[:passenger]
68
+ mkdir_p root / "public"
69
+ mkdir_p root / "tmp"
70
+ end
55
71
  end
56
72
 
57
73
  def copy_template_files
58
- cp Integrity.root / "config" / "config.sample.ru", root / "config.ru"
59
- cp Integrity.root / "config" / "config.sample.yml", root / "config.yml"
60
- cp Integrity.root / "config" / "thin.sample.yml", root / "thin.yml"
74
+ copy "config/config.sample.ru"
75
+ copy "config/config.sample.yml"
76
+ copy "config/thin.sample.yml" if options[:thin]
61
77
  end
62
78
 
63
79
  def edit_template_files
64
80
  edit_integrity_configuration
65
- edit_thin_configuration
81
+ edit_thin_configuration if options[:thin]
66
82
  end
67
83
 
68
84
  def edit_integrity_configuration
@@ -97,36 +113,9 @@ module Integrity
97
113
  puts %Q(Don't forget to tweak #{root / "config.yml"} to your needs.)
98
114
  end
99
115
 
100
- def set_up_migrations
101
- database_adapter.execute %q(CREATE TABLE "migration_info" ("migration_name" VARCHAR(255));)
102
- end
103
-
104
- def add_initial_migration
105
- database_adapter.execute %q(INSERT INTO "migration_info" ("migration_name") VALUES ("initial"))
106
- end
107
-
108
- def tables_from_before_migrations_exist?
109
- table_exists?("integrity_projects") &&
110
- table_exists?("integrity_builds") &&
111
- table_exists?("integrity_notifiers")
112
- end
113
-
114
- def migrations_already_set_up?
115
- table_exists?("migration_info")
116
- end
117
-
118
- def without_pluralizing_table_names
119
- database_adapter.resource_naming_convention = DataMapper::NamingConventions::Resource::Underscored
120
- yield
121
- database_adapter.resource_naming_convention = DataMapper::NamingConventions::Resource::UnderscoredAndPluralized
122
- end
123
-
124
- def table_exists?(table_name)
125
- database_adapter.storage_exists?(table_name)
126
- end
127
-
128
- def database_adapter
129
- DataMapper.repository(:default).adapter
116
+ def copy(path)
117
+ cp(File.dirname(__FILE__) + "/../../#{path}",
118
+ root.join(File.basename(path).gsub(/\.sample/, "")))
130
119
  end
131
120
  end
132
121
  end
@@ -2,13 +2,38 @@ require "dm-migrations"
2
2
  require "migration_runner"
3
3
 
4
4
  module Integrity
5
- class Migrations
6
- include DataMapper::Types
5
+ def self.migrate_db
6
+ setup_initial_migration if pre_migrations?
7
+ Integrity::Migrations.migrate_up!
8
+ end
9
+
10
+ def self.setup_initial_migration
11
+ database_adapter.execute %q(CREATE TABLE "migration_info" ("migration_name" VARCHAR(255));)
12
+ database_adapter.execute %q(INSERT INTO "migration_info" ("migration_name") VALUES ("initial"))
13
+ end
14
+
15
+ def self.pre_migrations?
16
+ !table_exists?("migration_info") &&
17
+ ( table_exists?("integrity_projects") &&
18
+ table_exists?("integrity_builds") &&
19
+ table_exists?("integrity_notifiers") )
20
+ end
21
+
22
+ def self.table_exists?(table_name)
23
+ database_adapter.storage_exists?(table_name)
24
+ end
25
+
26
+ def self.database_adapter
27
+ DataMapper.repository(:default).adapter
28
+ end
29
+
30
+ module Migrations
31
+ # This is what is actually happening:
32
+ # include DataMapper::MigrationRunner
7
33
 
8
- # not strictly necessary, but it makes it clear what is going on.
9
- include DataMapper::MigrationRunner
34
+ include DataMapper::Types
10
35
 
11
- migration 1, :initial, :verbose => false do
36
+ migration 1, :initial, :verbose => true do
12
37
  up do
13
38
  create_table :integrity_projects do
14
39
  column :id, Integer, :serial => true
@@ -46,15 +71,9 @@ module Integrity
46
71
  column :project_id, Integer
47
72
  end
48
73
  end
49
-
50
- down do
51
- drop_table :integrity_notifiers
52
- drop_table :integrity_projects
53
- drop_table :integrity_builds
54
- end
55
74
  end
56
75
 
57
- migration 2, :add_commits, :verbose => false do
76
+ migration 2, :add_commits, :verbose => true do
58
77
  up do
59
78
  class ::Integrity::Build
60
79
  property :commit_identifier, String
@@ -116,42 +135,6 @@ module Integrity
116
135
  :output => build.output)
117
136
  end
118
137
  end
119
-
120
- down do
121
- modify_table :integrity_builds do
122
- add_column :commit_identifier, String, :nullable => false
123
- add_column :commit_metadata, Yaml, :nullable => false
124
- add_column :project_id, Integer
125
- end
126
-
127
- # sqlite hodgepockery
128
- all_builds = Build.all.map {|b| b.freeze }
129
- drop_table :integrity_builds
130
- create_table :integrity_builds do
131
- column :id, Integer, :serial => true
132
- column :output, Text, :nullable => false, :default => ""
133
- column :successful, Boolean, :nullable => false, :default => false
134
- column :commit_identifier, String, :nullable => false
135
- column :commit_metadata, Yaml, :nullable => false
136
- column :created_at, DateTime
137
- column :updated_at, DateTime
138
- column :project_id, Integer
139
- end
140
-
141
- all_builds.each do |build|
142
- Build.create(:project_id => build.commit.project_id,
143
- :output => build.output,
144
- :successful => build.successful,
145
- :commit_identifier => build.commit.identifier,
146
- :commit_metadata => {
147
- :message => build.commit.message,
148
- :author => build.commit.author.full,
149
- :date => commit.committed_at
150
- }.to_yaml)
151
- end
152
-
153
- drop_table :commits
154
- end
155
138
  end
156
139
  end
157
140
  end
@@ -1,38 +1,40 @@
1
+ require File.dirname(__FILE__) + "/notifier/base"
2
+
1
3
  module Integrity
2
4
  class Notifier
3
5
  include DataMapper::Resource
4
-
5
- property :id, Serial
6
+
7
+ property :id, Integer, :serial => true
6
8
  property :name, String, :nullable => false
7
9
  property :config, Yaml, :nullable => false, :lazy => false
8
-
10
+
9
11
  belongs_to :project, :class_name => "Integrity::Project"
10
-
12
+
11
13
  validates_is_unique :name, :scope => :project_id
12
14
  validates_present :project_id
13
-
15
+
14
16
  def self.available
15
- @available ||= constants.map { |name| const_get(name) }.select { |notifier| valid_notifier?(notifier) }
17
+ constants.map { |name| const_get(name) }.select { |notifier| valid_notifier?(notifier) }
16
18
  end
17
-
19
+
18
20
  def self.enable_notifiers(project, enabled, config={})
19
21
  all(:project_id => project).destroy!
20
22
  list_of_enabled_notifiers(enabled).each do |name|
21
23
  create! :project_id => project, :name => name, :config => config[name]
22
24
  end
23
-
25
+
24
26
  end
25
-
27
+
26
28
  def notify_of_build(build)
27
29
  to_const.notify_of_build(build, config)
28
30
  end
29
-
31
+
30
32
  private
31
-
33
+
32
34
  def to_const
33
35
  self.class.module_eval(name)
34
36
  end
35
-
37
+
36
38
  def self.list_of_enabled_notifiers(names)
37
39
  [*names].reject { |n| n.nil? }
38
40
  end
@@ -44,7 +46,3 @@ module Integrity
44
46
  private_class_method :valid_notifier?
45
47
  end
46
48
  end
47
-
48
- require File.dirname(__FILE__) / "notifier" / "base"
49
-
50
- Dir["#{File.dirname(__FILE__)}/notifier/*.rb"].each &method(:require)
@@ -8,47 +8,57 @@ module Integrity
8
8
  def self.to_haml
9
9
  raise NoMethodError, "you need to implement this method in your notifier"
10
10
  end
11
-
12
- attr_reader :build
13
-
14
- def initialize(build, config)
15
- @build = build
11
+
12
+ attr_reader :commit
13
+
14
+ def initialize(commit, config)
15
+ @commit = commit
16
16
  @config = config
17
17
  end
18
-
18
+
19
+ def build
20
+ warn "Notifier::Base#build is deprecated, use Notifier::Base#commit instead"
21
+ commit
22
+ end
23
+
19
24
  def deliver!
20
25
  raise NoMethodError, "you need to implement this method in your notifier"
21
26
  end
22
-
27
+
23
28
  def short_message
24
- "Build #{build.short_commit_identifier} #{build.successful? ? "was successful" : "failed"}"
29
+ commit.human_readable_status
25
30
  end
26
-
31
+
27
32
  def full_message
28
33
  <<-EOM
29
- "Build #{build.commit_identifier} #{build.successful? ? "was successful" : "failed"}"
34
+ "Build #{commit.identifier} #{commit.successful? ? "was successful" : "failed"}"
30
35
 
31
- Commit Message: #{build.commit_message}
32
- Commit Date: #{build.commited_at}
33
- Commit Author: #{build.commit_author.name}
36
+ Commit Message: #{commit.message}
37
+ Commit Date: #{commit.committed_at}
38
+ Commit Author: #{commit.author.name}
34
39
 
35
- Link: #{build_url}
40
+ Link: #{commit_url}
36
41
 
37
42
  Build Output:
38
43
 
39
- #{stripped_build_output}
44
+ #{stripped_commit_output}
40
45
  EOM
41
46
  end
42
-
43
- def build_url
47
+
48
+ def commit_url
44
49
  raise if Integrity.config[:base_uri].nil?
45
- Integrity.config[:base_uri] / build.project.permalink / "builds" / build.commit_identifier
50
+ Integrity.config[:base_uri] / commit.project.permalink / "commits" / commit.identifier
46
51
  end
47
52
 
48
53
  private
49
54
 
55
+ def stripped_commit_output
56
+ commit.output.gsub("\e[0m", "").gsub(/\e\[3[1-7]m/, "")
57
+ end
58
+
50
59
  def stripped_build_output
51
- build.output.gsub("\e[0m", "").gsub(/\e\[3[1-7]m/, "")
60
+ warn "Notifier::Base#stripped_build_output is deprecated, use Notifier::base#stripped_commit_output instead"
61
+ stripped_commit_output
52
62
  end
53
63
  end
54
64
  end
@@ -0,0 +1,100 @@
1
+ require "hpricot"
2
+ require "haml"
3
+ require File.dirname(__FILE__) + "/../../integrity"
4
+
5
+ module Integrity
6
+ class Notifier
7
+ module TestHelpers
8
+ module HpricotAssertions
9
+ # Thanks Harry! http://gist.github.com/39960
10
+
11
+ class HpricotMatcher
12
+ def initialize(html)
13
+ @doc = Hpricot(html)
14
+ end
15
+
16
+ # elements('h1') returns a Hpricot::Elements object with all h1-tags.
17
+ def elements(selector)
18
+ @doc.search(selector)
19
+ end
20
+
21
+ # element('h1') returns Hpricot::Elem with first h1-tag, or nil if
22
+ # none exist.
23
+ def element(selector)
24
+ @doc.at(selector)
25
+ end
26
+
27
+ # tags('h1') returns the inner HTML of all matched elements mathed.
28
+ def tags(selector)
29
+ e = elements(selector)
30
+ e.map {|x| x.inner_html}
31
+ end
32
+
33
+ # tag('h1') returns the inner HTML of the first mached element, or
34
+ # nil if none matched.
35
+ def tag(selector)
36
+ e = element(selector)
37
+ e && e.inner_html
38
+ end
39
+ end
40
+
41
+ def assert_have_tag(html, selector, content=nil)
42
+ matcher = HpricotMatcher.new(html)
43
+ assert_equal content, matcher.tag(selector) if content
44
+ assert matcher.tag(selector)
45
+ end
46
+ end
47
+
48
+ module NotifierFormHelpers
49
+ include HpricotAssertions
50
+
51
+ def form(config={})
52
+ Haml::Engine.new(notifier_class.to_haml).
53
+ render(OpenStruct.new(:config => config))
54
+ end
55
+
56
+ def assert_form_have_tag(selector, options={})
57
+ content = options.delete(:content)
58
+ assert_have_tag(form(options), selector, content)
59
+ end
60
+
61
+ def assert_form_have_option(option, value=nil)
62
+ selector = "input##{notifier.downcase}_notifier_#{option}"
63
+ selector << "[@name='notifiers[#{notifier}][#{option}]']"
64
+ selector << "[@value='#{value}']" if value
65
+
66
+ assert_form_have_tag(selector, option => value)
67
+ end
68
+
69
+ def assert_form_have_options(*options)
70
+ options.each { |option| assert_form_have_option(option) }
71
+ end
72
+ end
73
+
74
+ include NotifierFormHelpers
75
+
76
+ def build
77
+ @build ||= Integrity::Build.gen(:successful)
78
+ end
79
+
80
+ def commit
81
+ @commit ||= build.commit
82
+ end
83
+
84
+ def notifier_class
85
+ Integrity::Notifier.const_get(notifier)
86
+ end
87
+
88
+ def notification
89
+ notifier_class.new(commit).body
90
+ end
91
+
92
+ def setup_database
93
+ DataMapper.setup(:default, "sqlite3::memory:")
94
+ DataMapper.auto_migrate!
95
+
96
+ require File.dirname(__FILE__) + "/../../../test/helpers/fixtures"
97
+ end
98
+ end
99
+ end
100
+ end