is the last sample's pending exam updates the sample status to 'finished' 4 Failure/Error: expect { 5 result should have been changed to 3, but is now nil 6 # ./spec/models/exam_spec.rb:44:in `block (4 levels) in <top (required)>'
is the last sample's pending exam updates the sample status to 'finished' 4 Failure/Error: expect { 5 result should have changed, but is still 3 6 # ./spec/models/exam_spec.rb:44:in `block (4 levels) in <top (required)>' 7 8 Finished in 0.07748 seconds 9 1 example, 1 failure
last sample's pending exam" do 42 it "updates the sample status to 'finished'" do 43 exam1 = sample.exams.create! :positive => true 44 exam2 = sample.exams.create! :positive => nil 45 expect { 46 exam2.record_result true 47 }.to change { sample.reload.status }.to Sample::Status::FINISHED 48 end 49 end 50 end
context "with category A" do 6 it "creates the exams for the respective category" do 7 expect { 8 Sample.create! :category => Sample::Category::A 9 }.to change { Exam.count }.by 2 10 end 11 end 12 end 13 end
module Category 5 A = 1 6 B = 2 7 end 8 9 private 10 def create_exams 11 return if category.blank? 12 patologies = case category 13 when Category::A 14 %w(blabla bleble) 15 when Category::B 16 %w(blibli bloblo) 17 end 18 patologies.each do |patology| 19 exams.create :patology => patology 20 end 21 end 22 end
sample was created more than 2 days ago" do 16 sample = Sample.create!( 17 :category => Sample::Category::A, 18 :created_at => 3.days.ago 19 ) 20 sample.should be_delayed 21 end 22 23 it "returns false if the sample was created less than 2 days ago" do 24 sample = Sample.create!( 25 :category => Sample::Category::A, 26 :created_at => 1.day.ago 27 ) 28 sample.should_not be_delayed 29 end 30 end
if the sample was created more than 2 days ago" do 3 16: sample = Sample.new(:category => Sample::Category::A) 4 17: sample.created_at = 3.days.ago 5 18: sample.save! 6 => 19: binding.pry 7 20: sample.should be_delayed 8 21: end 9 22: 10 23: it "returns false if the sample was created less than 2 days ago" do 11 24: sample = Sample.new(:category => Sample::Category::A) 12 13 (pry) #<RSpec::Core::ExampleGroup::Nested_1::Nested_2>: 0> sample.exams.count 14 => 2
Sample.create(attributes).tap do |sample| 5 create_exams_for sample 6 end 7 end 8 end 9 10 private 11 def create_exams_for(sample) 12 return if sample.category.blank? 13 patologies = case sample.category 14 when Sample::Category::A 15 %w(blabla bleble) 16 when Sample::Category::B 17 %w(blibli bloblo) 18 end 19 patologies.each do |patology| 20 sample.exams.create :patology => patology 21 end 22 end 23 end
it "aborts when the client has samples" do 6 client = Client.create! 7 client.samples.create! :category => Sample::Category::A 8 expect { client.destroy }.to_not change { Client.count } 9 end 10 11 it "succeeds when the client does not have samples" do 12 client = Client.create! 13 expect { client.destroy }.to change { Client.count } 14 end 15 end 16 end
must be sent to a third party" do 46 it "sends the exam" do 47 MyApiWrapper.should_receive(:send_exam) 48 Exam.create! :third_party => true 49 end 50 end 51 52 context "if the exam must not be sent to a third party" do 53 it "does not send the exam" do 54 MyApiWrapper.should_not_receive(:send_exam) 55 Exam.create! :third_party => false 56 end 57 end 58 end
4 end 5 6 def create(attributes) 7 @sample.exams.create(attributes).tap do |exam| 8 if should_send_to_third_party? exam 9 MyApiWrapper.send_exam(exam) 10 end 11 end 12 end 13 14 private 15 def should_send_to_third_party?(exam) 16 exam.valid? && exam.third_party? 17 end 18 end