Skip to content

Commit

Permalink
Ensure nil id_token doesn't break stuff - Fix #425
Browse files Browse the repository at this point in the history
  • Loading branch information
sethherr committed Aug 16, 2018
1 parent 1f9a92a commit 46fecd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/b_param.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def self.v2_params(hash)
end

def self.find_or_new_from_token(toke = nil, user_id: nil, organization_id: nil)
b = where(creator_id: user_id, id_token: toke).first if user_id.present?
b = where(creator_id: user_id, id_token: toke).first if toke.present? && user_id.present?
b ||= with_organization_or_no_creator(toke)
b ||= BParam.new(creator_id: user_id, params: { revised_new: true }.as_json)
b.creator_id ||= user_id
Expand Down
11 changes: 11 additions & 0 deletions spec/models/b_param_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@
end
end
end
context "with existing b_param with nil for id_token value - legacy issue" do
let(:b_param_nil) { FactoryGirl.create(:b_param, creator_id: user.id) }
it "does not return that BParam" do
b_param_nil.update_column :id_token, nil
b_param_nil.reload
result = BParam.find_or_new_from_token(nil, user_id: user.id)
expect(result.is_a?(BParam)).to be_truthy
expect(result.id).to be_nil
expect(result.creator_id).to eq user.id
end
end
end

describe 'safe_bike_hash' do
Expand Down

0 comments on commit 46fecd4

Please sign in to comment.