Skip to content

Commit

Permalink
Fix NoMethodError
Browse files Browse the repository at this point in the history
  • Loading branch information
penguoir committed Feb 15, 2024
1 parent 52fd730 commit 80a0770
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_cortex/generator/boolean.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def openai_error_message
end

def convert_to_boolean(content)
content = content.downcase.gsub(/[^a-z]/, "")
content = content&.downcase&.gsub(/[^a-z]/, "")

case content
when "yes", "true", "1"
Expand Down
7 changes: 7 additions & 0 deletions spec/active_cortex/generator/boolean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
end
end

context "when OpenAI returns an error" do
it "raises an error" do
stub_request(:post, "https://api.openai.com/v1/chat/completions").to_return(status: 500)
expect { generator.generation }.to raise_error(ActiveCortex::Error)
end
end

context "when saving the generation" do
it "saves the generation to the record", :vcr do
generator.save_generation
Expand Down

0 comments on commit 80a0770

Please sign in to comment.