docbrown/spec/models/html_variant_spec.rb
rhymes 6553f08d94 Rubocop cleanups (#1415)
* Update rubocop-todo.yml with new violations

* Fix Layout/EmptyLine* rules

* Fix Layout/Indentation* rules

* Fix remaining Layout/* rules

* Fix Lint/DuplicateMethods by removing unused accessor

* Fix Lint/IneffectiveAccessModifier

* Fix Lint/MissingCopEnableDirective

* Re-run rubocop auto gen config

* Fix Layout/RescueEnsureAlignment

* Fix Naming/* rules

* Fix some RSpec/* rules

* Fix typos

* Fix RSpec/LetBeforeExamples

* Series should only be an attr_writer, not an attr_accessor

* Fix RSpec/InstanceVariable

* Fix RSpec/InstanceVariable

* Fix RSpec/RepeatedDescription and RSpec/RepeatedExample

* Fix Style/ClassAndModuleChildren

* Fix Style/ConditionalAssignment

* Fix some Style/* rules

* Trigger Travis CI build because failing tests are not failing locally

* Revert "Fix Style/ClassAndModuleChildren"

This reverts commit 1686801d8a1516ba1894f79e24401a20dea65f99.
2019-01-02 11:20:02 -05:00

38 lines
1.4 KiB
Ruby

require "rails_helper"
RSpec.describe HtmlVariant, type: :model do
let(:html_variant) { create(:html_variant, approved: true, published: true) }
it { is_expected.to validate_uniqueness_of(:name) }
it { is_expected.to validate_presence_of(:html) }
it { is_expected.to belong_to(:user) }
it "calculates success rate" do
HtmlVariantTrial.create!(html_variant_id: html_variant.id)
HtmlVariantTrial.create!(html_variant_id: html_variant.id)
HtmlVariantTrial.create!(html_variant_id: html_variant.id)
HtmlVariantTrial.create!(html_variant_id: html_variant.id)
HtmlVariantSuccess.create!(html_variant_id: html_variant.id)
html_variant.calculate_success_rate!
expect(html_variant.success_rate).to eq(0.025)
end
it "finds for test without tag" do
html_variant.save!
expect(HtmlVariant.find_for_test.id).to eq(html_variant.id)
end
it "finds for test with tag given" do
html_variant.target_tag = "hello"
html_variant.save!
expect(HtmlVariant.find_for_test(["hello"]).id).to eq(html_variant.id)
end
it "does not find if different tag targeted" do
html_variant.target_tag = "different_tag_yolo"
html_variant.save!
expect(HtmlVariant.find_for_test(["hello"])).to eq(nil)
end
it "finds if no tag targeted and tag given" do
html_variant.save!
expect(HtmlVariant.find_for_test(["hello"]).id).to eq(html_variant.id)
end
end