Last active
August 29, 2015 14:19
-
-
Save jcutrell/22a1da1ca068322ffb86 to your computer and use it in GitHub Desktop.
Weird behavior...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseJob < ActiveRecord::Base | |
belongs_to :child_job, polymorphic: true | |
has_attached_file :header_image, :styles => { :medium => "800x500#" } | |
validates_attachment_content_type :header_image, :content_type => /\Aimage\/.*\Z/ | |
validates :title, presence: true | |
validates :prompt_html, presence: true | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LinkJob < ActiveRecord::Base | |
include BaseJobMethods | |
has_one :base_job, as: :child_job | |
has_many :job_completions, as: :job | |
belongs_to :redirector | |
accepts_nested_attributes_for :base_job | |
validates :base_job, presence: true | |
validates :redirector, presence: true | |
def completed_by_user?(user) | |
false if user.nil? | |
user.has_completed_job?(self) | |
end | |
def has_user_met_requirements?(user) | |
false if user.nil? | |
user.redirector_clicks.where(redirector_id: redirector.id).exists? | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rails_helper' | |
RSpec.describe LinkJob, type: :model do | |
it { should validate_presence_of :base_job } | |
it { should validate_presence_of :redirector } | |
it "should return true when asked if it is #persisted?" do | |
link_job = create(:link_job) | |
expect(LinkJob.count).to eq(1) | |
expect(link_job.redirector.persisted?).to eq(true) | |
expect(link_job.base_job.persisted?).to eq(true) | |
expect(link_job.new_record?).to eq(false) | |
expect(link_job.destroyed?).to eq(false) | |
expect(link_job.persisted?).to eq(true) # fails here... | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Redirector < ActiveRecord::Base | |
has_many :redirector_clicks | |
has_one :link_job | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As it turns out, the
include BaseJobMethods
line referenced a module that included ActiveRecord::Base. Removing that inclusion fixed the issue.