diff --git a/app/models/b_param.rb b/app/models/b_param.rb index cfe0cfae02..dcc1079028 100644 --- a/app/models/b_param.rb +++ b/app/models/b_param.rb @@ -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 diff --git a/spec/models/b_param_spec.rb b/spec/models/b_param_spec.rb index 1d954dd6fb..072b1d7bdb 100644 --- a/spec/models/b_param_spec.rb +++ b/spec/models/b_param_spec.rb @@ -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