{"action":"created","issue":{"url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/297","labels_url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/297/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/297/comments","events_url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/297/events","html_url":"https://github.com/thoughtbot/shoulda-matchers/issues/297","id":14381084,"number":297,"title":"validates_presence_of ignores my after_initialize method, causing it to fail.","user":{"login":"draffauf","id":869015,"avatar_url":"https://avatars.githubusercontent.com/u/869015?v=3","gravatar_id":"","url":"https://api.github.com/users/draffauf","html_url":"https://github.com/draffauf","followers_url":"https://api.github.com/users/draffauf/followers","following_url":"https://api.github.com/users/draffauf/following{/other_user}","gists_url":"https://api.github.com/users/draffauf/gists{/gist_id}","starred_url":"https://api.github.com/users/draffauf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/draffauf/subscriptions","organizations_url":"https://api.github.com/users/draffauf/orgs","repos_url":"https://api.github.com/users/draffauf/repos","events_url":"https://api.github.com/users/draffauf/events{/privacy}","received_events_url":"https://api.github.com/users/draffauf/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2013-05-15T21:47:52Z","updated_at":"2015-07-22T22:26:33Z","closed_at":"2013-05-19T07:44:22Z","body":"~~~\r\n13:53:06 guard.1 |   4) LineItem \r\n13:53:06 guard.1 |      Failure/Error: it { should validate_presence_of(:quantity).with_message(\"Please enter a quantity.\") }\r\n13:53:06 guard.1 |      NoMethodError:\r\n13:53:06 guard.1 |        undefined method `*' for nil:NilClass\r\n13:53:06 guard.1 |      # ./app/models/line_item.rb:147:in `total_price'\r\n13:53:06 guard.1 |      # ./app/models/line_item.rb:217:in `set_price'\r\n13:53:06 guard.1 |      # ./spec/models/line_item_spec.rb:32:in `block (2 levels) in <top (required)>'\r\n\r\n# /app/models/line_item:\r\n...\r\nafter_initialize :init\r\nbefore_validation :set_document, :set_product, :set_price\r\n...\r\ndef init\r\n  self.provided_on\t||= Date.today\t\t\r\n  self.quantity \t\t||= 0\r\n  self.unit_price\t\t||= 0\r\nend\r\n\r\ndef set_price\r\n  self.price = total_price\r\nend\r\n\r\ndef total_price\r\n  quantity * unit_price\r\nend\r\n...\r\n~~~"},"comment":{"url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/comments/123888523","html_url":"https://github.com/thoughtbot/shoulda-matchers/issues/297#issuecomment-123888523","issue_url":"https://api.github.com/repos/thoughtbot/shoulda-matchers/issues/297","id":123888523,"user":{"login":"mcmire","id":7371,"avatar_url":"https://avatars.githubusercontent.com/u/7371?v=3","gravatar_id":"","url":"https://api.github.com/users/mcmire","html_url":"https://github.com/mcmire","followers_url":"https://api.github.com/users/mcmire/followers","following_url":"https://api.github.com/users/mcmire/following{/other_user}","gists_url":"https://api.github.com/users/mcmire/gists{/gist_id}","starred_url":"https://api.github.com/users/mcmire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcmire/subscriptions","organizations_url":"https://api.github.com/users/mcmire/orgs","repos_url":"https://api.github.com/users/mcmire/repos","events_url":"https://api.github.com/users/mcmire/events{/privacy}","received_events_url":"https://api.github.com/users/mcmire/received_events","type":"User","site_admin":false},"created_at":"2015-07-22T22:26:33Z","updated_at":"2015-07-22T22:26:33Z","body":"The default subject is `described_class.new`, so that wouldn't fix this.\r\n\r\nChecking for `quantity` to be nil inside of `total_price` would, though."}}