Permalink
Browse files

All tests passing, using factory_girl, silencing vendor error trace

  • Loading branch information...
1 parent daba80f commit 6d558e1485d393d9ef477238925b78e29c718232 @dce dce committed Oct 22, 2009
Showing with 3,281 additions and 120 deletions.
  1. +1 −11 app/helpers/sites_helper.rb
  2. +11 −21 app/models/site.rb
  3. +7 −7 app/routes/sites.rb
  4. +1 −1 app/views/index.rb
  5. +1 −0 dependencies
  6. +1 −0 init.rb
  7. +0 −8 test/factories.rb
  8. +11 −0 test/factories/site.rb
  9. +14 −14 test/stories/sites_test.rb
  10. +6 −20 test/test_helper.rb
  11. +26 −38 test/unit/site_test.rb
  12. +9 −0 vendor/factory_girl-1.2.3/CONTRIBUTION_GUIDELINES.rdoc
  13. +29 −0 vendor/factory_girl-1.2.3/Changelog
  14. +19 −0 vendor/factory_girl-1.2.3/LICENSE
  15. +228 −0 vendor/factory_girl-1.2.3/README.rdoc
  16. +81 −0 vendor/factory_girl-1.2.3/Rakefile
  17. +35 −0 vendor/factory_girl-1.2.3/lib/factory_girl.rb
  18. +50 −0 vendor/factory_girl-1.2.3/lib/factory_girl/aliases.rb
  19. +29 −0 vendor/factory_girl-1.2.3/lib/factory_girl/attribute.rb
  20. +20 −0 vendor/factory_girl-1.2.3/lib/factory_girl/attribute/association.rb
  21. +16 −0 vendor/factory_girl-1.2.3/lib/factory_girl/attribute/callback.rb
  22. +20 −0 vendor/factory_girl-1.2.3/lib/factory_girl/attribute/dynamic.rb
  23. +17 −0 vendor/factory_girl-1.2.3/lib/factory_girl/attribute/static.rb
  24. +395 −0 vendor/factory_girl-1.2.3/lib/factory_girl/factory.rb
  25. +79 −0 vendor/factory_girl-1.2.3/lib/factory_girl/proxy.rb
  26. +21 −0 vendor/factory_girl-1.2.3/lib/factory_girl/proxy/attributes_for.rb
  27. +30 −0 vendor/factory_girl-1.2.3/lib/factory_girl/proxy/build.rb
  28. +12 −0 vendor/factory_girl-1.2.3/lib/factory_girl/proxy/create.rb
  29. +50 −0 vendor/factory_girl-1.2.3/lib/factory_girl/proxy/stub.rb
  30. +63 −0 vendor/factory_girl-1.2.3/lib/factory_girl/sequence.rb
  31. +54 −0 vendor/factory_girl-1.2.3/lib/factory_girl/step_definitions.rb
  32. +12 −0 vendor/factory_girl-1.2.3/lib/factory_girl/syntax.rb
  33. +42 −0 vendor/factory_girl-1.2.3/lib/factory_girl/syntax/blueprint.rb
  34. +68 −0 vendor/factory_girl-1.2.3/lib/factory_girl/syntax/generate.rb
  35. +39 −0 vendor/factory_girl-1.2.3/lib/factory_girl/syntax/make.rb
  36. +42 −0 vendor/factory_girl-1.2.3/lib/factory_girl/syntax/sham.rb
  37. +29 −0 vendor/factory_girl-1.2.3/spec/factory_girl/aliases_spec.rb
  38. +29 −0 vendor/factory_girl-1.2.3/spec/factory_girl/attribute/association_spec.rb
  39. +23 −0 vendor/factory_girl-1.2.3/spec/factory_girl/attribute/callback_spec.rb
  40. +49 −0 vendor/factory_girl-1.2.3/spec/factory_girl/attribute/dynamic_spec.rb
  41. +29 −0 vendor/factory_girl-1.2.3/spec/factory_girl/attribute/static_spec.rb
  42. +30 −0 vendor/factory_girl-1.2.3/spec/factory_girl/attribute_spec.rb
  43. +571 −0 vendor/factory_girl-1.2.3/spec/factory_girl/factory_spec.rb
  44. +52 −0 vendor/factory_girl-1.2.3/spec/factory_girl/proxy/attributes_for_spec.rb
  45. +81 −0 vendor/factory_girl-1.2.3/spec/factory_girl/proxy/build_spec.rb
  46. +94 −0 vendor/factory_girl-1.2.3/spec/factory_girl/proxy/create_spec.rb
  47. +79 −0 vendor/factory_girl-1.2.3/spec/factory_girl/proxy/stub_spec.rb
  48. +84 −0 vendor/factory_girl-1.2.3/spec/factory_girl/proxy_spec.rb
  49. +66 −0 vendor/factory_girl-1.2.3/spec/factory_girl/sequence_spec.rb
  50. +34 −0 vendor/factory_girl-1.2.3/spec/factory_girl/syntax/blueprint_spec.rb
  51. +57 −0 vendor/factory_girl-1.2.3/spec/factory_girl/syntax/generate_spec.rb
  52. +35 −0 vendor/factory_girl-1.2.3/spec/factory_girl/syntax/make_spec.rb
  53. +35 −0 vendor/factory_girl-1.2.3/spec/factory_girl/syntax/sham_spec.rb
  54. +304 −0 vendor/factory_girl-1.2.3/spec/integration_spec.rb
  55. +43 −0 vendor/factory_girl-1.2.3/spec/models.rb
  56. +18 −0 vendor/factory_girl-1.2.3/spec/spec_helper.rb
@@ -24,17 +24,7 @@ def email_input(value = nil)
end
def site_errors
- errors = site.errors.present do |e|
- e.on [:name, :not_present], "Name should be present"
- e.on [:url, :not_present], "URL should be present"
- e.on [:url, :format], "URL should follow standard format"
- e.on [:threshold, :not_present], "# of retries should be present"
- e.on [:email, :not_present], "Email address should be present"
- e.on [:email, :format], "Email address should follow standard format"
- e.on [:account, :not_present], "You should supply an account"
- end
-
- errors.map {|e| { :message => e} }
+ errors = site.errors.map {|attr, msg| { :message => "#{attr} #{msg}" } }
end
end
end
View
@@ -22,43 +22,33 @@ def self.http_url
end
end
- def save_with_monit_callback
- if result = save_without_monit_callback
- create_monit_check
- end
- result
- end
- private :save_with_monit_callback
- alias_method_chain :save, :monit_callback
+ after_save :create_monit_check
- def validate
- assert_present :name
- assert_present :url
- assert_present :threshold
- assert_present :email
+ validates_presence_of :name
+ validates_presence_of :url
+ validates_presence_of :threshold
+ validates_presence_of :email
- assert_unique :url
+ validates_uniqueness_of :url
- assert_format :email, Regex.email
- assert_format :url, Regex.http_url
- end
+ validates_format_of :email, :with => Regex.email, :allow_nil => true
+ validates_format_of :url, :with => Regex.http_url, :allow_nil => true
def host
URI.parse(url).host
end
- def latest_status
- status_record.sort(:order => "DESC", :limit => 1).first
- end
-
private
def create_monit_check
@template = MonitCheck.new(self)
File.open(root_path('monitrc', RACK_ENV, "#{self.id}.monitrc"), 'w') do |file|
file << @template.render
end
+
FileUtils.chmod 0700, root_path('monitrc', RACK_ENV, "#{self.id}.monitrc")
system "#{File.join(settings(:monit_bin_dir), 'monit')} #{settings(:monit_cli_options)} reload"
+
+ return true
end
end
View
@@ -18,32 +18,32 @@ class Main
end
get "/sites/:id" do
- @site = Site[params[:id]]
+ @site = Site.find(params[:id])
mustache :show_site
end
get "/sites/:id/edit" do
- @site = Site[params[:id]]
+ @site = Site.find(params[:id])
mustache :edit_site
end
put "/sites/:id" do
- @site = Site[params[:id]]
- if @site.update(params[:site])
+ @site = Site.find(params[:id])
+ if @site.update_attributes(params[:site])
redirect "/sites/#{@site.id}"
else
mustache :edit_site
end
end
delete "/sites/:id" do
- Site[params[:id]].delete
+ Site.find(params[:id]).delete
redirect '/'
end
post "/sites/:id/status" do
- @site = Site[params[:id]]
- @site.status_record << params[:status]
+ @site = Site.find(params[:id])
+ @site.update_attribute(:status_record, params[:status])
""
end
end
View
@@ -9,7 +9,7 @@ def sites
:id => site.id,
:name => site.name,
:url => site.url,
- :status => site.latest_status
+ :status => site.status_record
}
end
end
View
@@ -12,3 +12,4 @@ faker 0.3.1 (test) git://github.com/yyyc514/faker.git
rack-test 0.5.0 (test) git://github.com/brynary/rack-test.git
webrat 0.5.3 (test) git://github.com/brynary/webrat.git
mocha 0.9.8 (test)
+factory_girl 1.2.3 (test)
View
@@ -23,6 +23,7 @@ class Main < Monk::Glue
configure do
# Set up ActiveRecord
@db_config = YAML.load(File.open('config/database.yml'))
+ ActiveRecord::Base.configurations = @db_config
ActiveRecord::Base.establish_connection(@db_config[Main.environment.to_s])
# Load all application files.
View
@@ -1,8 +0,0 @@
-Site.factory do
- name "Google"
- url proc { "http://www.google.com/intl/en/help/features.html?rand=#{rand(9999)}" }
- match_text "feeling lucky"
- threshold 5
- email "admin@google.com"
-end
-
@@ -0,0 +1,11 @@
+Factory.sequence :url do |n|
+ "http://www.google.com/intl/en/help/features.html?rand=#{n}"
+end
+
+Factory.define :site do |s|
+ s.name "Google"
+ s.url { Factory.next(:url) }
+ s.match_text "feeling lucky"
+ s.threshold 5
+ s.email "admin@google.com"
+end
@@ -3,7 +3,7 @@
class SitesTest < Test::Unit::TestCase
story "I should be able to visit the home page which is a list of sites" do
scenario "A visitor goes to the root URL" do
- site = Site.factory.save
+ site = Factory(:site)
visit "/"
@@ -13,7 +13,7 @@ class SitesTest < Test::Unit::TestCase
end
scenario "A visitor goes to the sites list" do
- site = Site.factory.save
+ site = Factory(:site)
visit "/sites"
@@ -64,22 +64,22 @@ class SitesTest < Test::Unit::TestCase
story "I should be able to view details about a site" do
scenario "A user goes to the site page" do
- site = Site.factory.save
+ site = Factory(:site)
visit "/sites/#{site.id}"
assert_contain "feeling lucky"
end
end
story "I should be able to edit details about a site" do
scenario "A user goes to the site edit page" do
- site = Site.factory.save
+ site = Factory(:site)
visit "/sites/#{site.id}/edit"
assert_have_selector 'form textarea[name="site[match_text]"]'
assert_contain "feeling lucky"
end
scenario "A user updates a site record" do
- site = Site.factory.save
+ site = Factory(:site)
visit "/sites/#{site.id}/edit"
fill_in "email", :with => "newuser@example.com"
click_button "save"
@@ -90,7 +90,7 @@ class SitesTest < Test::Unit::TestCase
end
scenario "A user updates a site record with invalid data" do
- site = Site.factory.save
+ site = Factory(:site)
visit "/sites/#{site.id}/edit"
fill_in "email", :with => "xxxxx"
click_button "save"
@@ -102,32 +102,32 @@ class SitesTest < Test::Unit::TestCase
story "I should be able to delete a site" do
scenario "A user goes to a site page and hits delete" do
- site = Site.factory(:name => "Yahoo").save
+ site = Factory(:site, :name => "Yahoo")
visit "/sites/#{site.id}"
click_button "delete"
- assert_equal nil, Site[site.id]
+ assert_equal nil, Site.find_by_id(site.id)
assert_not_contain "Yahoo"
end
end
story "monit should be able update the satus of a site" do
scenario "monit hits the API endpoint with a success status" do
- site = Site.factory.save
+ site = Factory(:site)
visit "/sites/#{site.id}/status", :post, {:status => "success"}
- site = Site[site.id]
- assert_equal site.status_record.sort(:order => "DESC", :limit => 1).first, "success"
+ site = Site.find(site.id)
+ assert_equal "success", site.status_record
end
scenario "monit hits the API endpoint with a fail status" do
- site = Site.factory.save
+ site = Factory(:site)
visit "/sites/#{site.id}/status", :post, {:status => "fail"}
- site = Site[site.id]
- assert_equal site.status_record.sort(:order => "DESC", :limit => 1).first, "fail"
+ site = Site.find(site.id)
+ assert_equal "fail", site.status_record
end
end
View
@@ -5,8 +5,9 @@
require "rack/test"
require "contest"
require "quietbacktrace"
-require 'active_support/testing/assertions'
-require 'mocha'
+require "active_support/testing/assertions"
+require "mocha"
+require "factory_girl"
Debugger.start
Debugger.settings[:autoeval] = true
@@ -41,26 +42,11 @@ def assert_does_not_contain(collection, x, extra_msg = "")
assert(!collection.include?(x), msg)
end
end
-end
-module Factory
- class Options
- def method_missing(method, *args)
- @records ||= {}
- @records[method] = args.first
- @records
- end
+ self.new_backtrace_silencer :vendor do |line|
+ line.include? 'vendor'
end
- def factory(options = {}, &block)
- if block_given?
- @default_options = Options.new.instance_eval(&block)
- else
- options = (@default_options || {}).merge(options)
- options.each {|k,v| options[k] = v.call if v.is_a?(Proc) }
- self.new(options)
- end
- end
+ self.backtrace_silencers << :vendor
end
-require "factories"
Oops, something went wrong.

0 comments on commit 6d558e1

Please sign in to comment.