From 32ae3876a99f0eb31c4c4d530cad64f199fcecdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=20Belik=C4=B1r=C4=B1k?= Date: Tue, 8 Feb 2022 18:36:30 +0000 Subject: [PATCH 1/5] Rspec for intgration:boolean_accessor added --- spec/models/integration_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/spec/models/integration_spec.rb b/spec/models/integration_spec.rb index 48d8ba975b68ae..a986cd8b4908fb 100644 --- a/spec/models/integration_spec.rb +++ b/spec/models/integration_spec.rb @@ -1021,4 +1021,24 @@ def fields ) end end + + + describe 'boolean_accessor' do + class TestIntegration < Integration + boolean_accessor :test + end + + let(:integration) { TestIntegration.create(properties: { test: test_property_value }) } + let(:test_property_value) { 'true' } + + it 'adds a boolean acessor for property' do + expect(integration.test?).to eq(true) + end + + let(:test_property_value) { '' } + it 'return nil for empty property' do + expect(integration.test?).to eq(nil) + end + end + end -- GitLab From a4b7d3fa45c26fa57d0be7beb2baa6c0b7654a86 Mon Sep 17 00:00:00 2001 From: Sean Gregory Date: Fri, 18 Mar 2022 11:30:06 -0400 Subject: [PATCH 2/5] Updates specs around ::boolean_accessor This commit builds off the work from @ByAlu which tests the boolean_accessor method implementation --- spec/models/integration_spec.rb | 92 +++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 10 deletions(-) diff --git a/spec/models/integration_spec.rb b/spec/models/integration_spec.rb index a986cd8b4908fb..cfef7e9b88e3f9 100644 --- a/spec/models/integration_spec.rb +++ b/spec/models/integration_spec.rb @@ -1024,21 +1024,93 @@ def fields describe 'boolean_accessor' do - class TestIntegration < Integration - boolean_accessor :test + let(:klass) do + Class.new(Integration) do + boolean_accessor :test + end end - let(:integration) { TestIntegration.create(properties: { test: test_property_value }) } - let(:test_property_value) { 'true' } + it 'with a value of true' do + with_properties(test: true) do |integration| + expect(integration.test).to be(true) + expect(integration.test?).to be(true) + end + end - it 'adds a boolean acessor for property' do - expect(integration.test?).to eq(true) + it 'with a value of false' do + with_properties(test: false) do |integration| + expect(integration.test).to be(false) + expect(integration.test?).to be(false) + end end - let(:test_property_value) { '' } - it 'return nil for empty property' do - expect(integration.test?).to eq(nil) + it 'with a value of 1' do + with_properties(test: 1) do |integration| + expect(integration.test).to be(true) + expect(integration.test?).to be(true) + end + end + + it 'with a value of 0' do + with_properties(test: 0) do |integration| + expect(integration.test).to be(false) + expect(integration.test?).to be(false) + end end - end + it 'with a value of "1"' do + with_properties(test: '1') do |integration| + expect(integration.test).to be(true) + expect(integration.test?).to be(true) + end + end + + it 'with a value of "0"' do + with_properties(test: '0') do |integration| + expect(integration.test).to be(false) + expect(integration.test?).to be(false) + end + end + + it 'with a value of "true"' do + with_properties(test: 'true') do |integration| + expect(integration.test).to be(true) + expect(integration.test?).to be(true) + end + end + + it 'with a value of "false"' do + with_properties(test: 'false') do |integration| + expect(integration.test).to be(false) + expect(integration.test?).to be(false) + end + end + + it 'with a string value' do + with_properties(test: 'foobar') do |integration| + expect(integration.test).to be(nil) + expect(integration.test?).to be(false) + end + end + + it 'with an empty string' do + with_properties(test: '') do |integration| + expect(integration.test).to be(nil) + expect(integration.test?).to be(false) + end + end + + it 'with a value of nil' do + with_properties(test: nil) do |integration| + expect(integration.test).to be(nil) + expect(integration.test?).to be(false) + end + end + + private + + def with_properties(**hargs) + yield klass.create(properties: hargs) + end + end end -- GitLab From 841caaeb2d06fea4fe49d44037e9fdd72b0aa18b Mon Sep 17 00:00:00 2001 From: Sean Gregory Date: Fri, 18 Mar 2022 11:44:28 -0400 Subject: [PATCH 3/5] Fix rubocop violations --- spec/models/integration_spec.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/models/integration_spec.rb b/spec/models/integration_spec.rb index cfef7e9b88e3f9..0570659d1a1177 100644 --- a/spec/models/integration_spec.rb +++ b/spec/models/integration_spec.rb @@ -1022,7 +1022,6 @@ def fields end end - describe 'boolean_accessor' do let(:klass) do Class.new(Integration) do @@ -1110,7 +1109,9 @@ def fields private def with_properties(**hargs) + # rubocop:disable Rails/SaveBang yield klass.create(properties: hargs) + # rubocop:enable Rails/SaveBang end end end -- GitLab From 20e35d6d052245ddd3ff9712accddc1f0e4cb94e Mon Sep 17 00:00:00 2001 From: Sean Gregory Date: Mon, 21 Mar 2022 09:03:14 -0400 Subject: [PATCH 4/5] Consolidate examples into a table --- spec/models/integration_spec.rb | 100 ++++++++------------------------ 1 file changed, 24 insertions(+), 76 deletions(-) diff --git a/spec/models/integration_spec.rb b/spec/models/integration_spec.rb index 0570659d1a1177..54121b224f768f 100644 --- a/spec/models/integration_spec.rb +++ b/spec/models/integration_spec.rb @@ -1025,93 +1025,41 @@ def fields describe 'boolean_accessor' do let(:klass) do Class.new(Integration) do - boolean_accessor :test + boolean_accessor :test_value end end - it 'with a value of true' do - with_properties(test: true) do |integration| - expect(integration.test).to be(true) - expect(integration.test?).to be(true) - end - end - - it 'with a value of false' do - with_properties(test: false) do |integration| - expect(integration.test).to be(false) - expect(integration.test?).to be(false) - end - end - - it 'with a value of 1' do - with_properties(test: 1) do |integration| - expect(integration.test).to be(true) - expect(integration.test?).to be(true) - end - end - - it 'with a value of 0' do - with_properties(test: 0) do |integration| - expect(integration.test).to be(false) - expect(integration.test?).to be(false) - end - end - - it 'with a value of "1"' do - with_properties(test: '1') do |integration| - expect(integration.test).to be(true) - expect(integration.test?).to be(true) - end - end - - it 'with a value of "0"' do - with_properties(test: '0') do |integration| - expect(integration.test).to be(false) - expect(integration.test?).to be(false) - end - end - - it 'with a value of "true"' do - with_properties(test: 'true') do |integration| - expect(integration.test).to be(true) - expect(integration.test?).to be(true) - end + where(:input, :method_result, :predicate_method_result) do + true | true | true + false | false | false + 1 | true | true + 0 | false | false + '1' | true | true + '0' | false | false + 'true' | true | true + 'false' | false | false + 'foobar' | nil | false + '' | nil | false + nil | nil | false + 'on' | true | true + 'off' | false | false + 'yes' | true | true + 'no' | false | false end - it 'with a value of "false"' do - with_properties(test: 'false') do |integration| - expect(integration.test).to be(false) - expect(integration.test?).to be(false) - end - end - - it 'with a string value' do - with_properties(test: 'foobar') do |integration| - expect(integration.test).to be(nil) - expect(integration.test?).to be(false) - end - end - - it 'with an empty string' do - with_properties(test: '') do |integration| - expect(integration.test).to be(nil) - expect(integration.test?).to be(false) - end - end - - it 'with a value of nil' do - with_properties(test: nil) do |integration| - expect(integration.test).to be(nil) - expect(integration.test?).to be(false) + with_them do + it 'returns an expected value' do + with_properties(test_value: input) do |integration| + expect(integration.test_value).to be(method_result) + expect(integration.test_value?).to be(predicate_method_result) + end end end private def with_properties(**hargs) - # rubocop:disable Rails/SaveBang - yield klass.create(properties: hargs) - # rubocop:enable Rails/SaveBang + yield klass.new(properties: hargs) end end end -- GitLab From ea735c40d14a1c837155f437b6655b9ed3d8f348 Mon Sep 17 00:00:00 2001 From: Sean Gregory Date: Mon, 21 Mar 2022 13:39:24 -0400 Subject: [PATCH 5/5] Refactor boolean_accessor examples --- spec/models/integration_spec.rb | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/spec/models/integration_spec.rb b/spec/models/integration_spec.rb index 54121b224f768f..fb8e8a9b5ad996 100644 --- a/spec/models/integration_spec.rb +++ b/spec/models/integration_spec.rb @@ -1029,6 +1029,8 @@ def fields end end + let(:integration) { klass.new(properties: { test_value: input }) } + where(:input, :method_result, :predicate_method_result) do true | true | true false | false | false @@ -1045,21 +1047,28 @@ def fields 'off' | false | false 'yes' | true | true 'no' | false | false + 'n' | false | false + 'y' | true | true + 't' | true | true + 'f' | false | false end with_them do - it 'returns an expected value' do - with_properties(test_value: input) do |integration| - expect(integration.test_value).to be(method_result) - expect(integration.test_value?).to be(predicate_method_result) - end + it 'has the correct value' do + expect(integration).to have_attributes( + test_value: be(method_result), + test_value?: be(predicate_method_result) + ) end end - private + it 'returns values when initialized without input' do + integration = klass.new - def with_properties(**hargs) - yield klass.new(properties: hargs) + expect(integration).to have_attributes( + test_value: be(nil), + test_value?: be(false) + ) end end end -- GitLab