docbrown/spec/forms/creator_settings_form_spec.rb
Ridhwana e250b46ed2
Using a Form Object that will persist for the Creator Settings Form (#15684)
* WIP: add a creatore settings form

* WIP: updat the controller to use the Creator Settings FOREM

* feat: use the creator settings form for the new action

* feat: add some default values for the new action

* a note about form data

* update the initiaize function to set some default values

* feat: update the form to use the model data

* feat: permit adn use the attributes within creator_settings_form

* update the flash error

* refactor: require and permit parameters

* chore: use booleans, set defaults and validate the form

* spec: update all the creator_settings tests

* chore: remove comment

* refactor: use self

* feat: aggregate failures'

* chore: remove the logo uploader in the controller

* refactor: update error handling

* feat: update the wasy the controller handles success and error

* chore: remove the resource errors

* feat: show flash message on new line

* fix: use a redirect so that we can get back to /new

* refactor: pass these values through as they seem to be caching whne setting them as default

* chore: change default values

* spec: update tests

* Fix CreatorSettingsForm specs

* fix: use a boolean for public

* spec: add another test for the success var

* fix: radio button labels to correspond + cyress specs

* spec: update based on new changes

* spec: update the params and the expected output

* spec: update the comments and status

* feat: no need for the initialize as we use Active Record Attributes

* feat: update the tac and coc to be persisted when ticked

* fix: amend spec

* blank space

* Message

Co-authored-by: Michael Kohl <me@citizen428.net>
2021-12-10 17:07:40 +02:00

64 lines
2.5 KiB
Ruby

require "rails_helper"
RSpec.describe CreatorSettingsForm, type: :model do
describe "validations" do
it { is_expected.to validate_presence_of(:community_name) }
it { is_expected.to validate_presence_of(:primary_brand_color_hex) }
end
describe "attributes" do
it "has the correct attribute names" do
expect(described_class.attribute_names).to eq(%w[checked_code_of_conduct checked_terms_and_conditions
community_name invite_only_mode logo
primary_brand_color_hex public])
end
it "sets default values", :aggregate_failures do
attributes = described_class.new.attributes
expect(attributes["checked_code_of_conduct"]).to be(false)
expect(attributes["checked_terms_and_conditions"]).to be(false)
end
end
describe "initializer" do
it "updates the values when we pass an attribute as a param", :aggregate_failures do
attributes = described_class.new(
primary_brand_color_hex: "#0a0a0a",
invite_only_mode: false,
).attributes
expect(attributes["primary_brand_color_hex"]).to eq("#0a0a0a")
expect(attributes["invite_only_mode"]).to eq(false)
end
end
describe "#save" do
let(:current_user) { create(:user) }
# rubocop:disable RSpec/ExampleLength
it "saves the updated attributes to the correct Settings values", :aggregate_failures do
# NOTE: override the profile migration hack from rails_helper.rb
# TODO: remove this once we remove it in rails_helper.rb
allow(Settings::UserExperience).to receive(:public).and_call_original
creator_settings_form = described_class.new(
checked_code_of_conduct: true,
checked_terms_and_conditions: true,
community_name: "Climbing Life",
invite_only_mode: false,
public: false,
primary_brand_color_hex: "#a81adb",
)
expect(creator_settings_form.valid?).to be(true)
creator_settings_form.save
expect(creator_settings_form.success).to be(true)
expect(Settings::Community.community_name).to eq("Climbing Life")
expect(Settings::UserExperience.primary_brand_color_hex).to eq("#a81adb")
expect(Settings::UserExperience.public).to eq(false)
expect(Settings::Authentication.invite_only_mode).to eq(false)
expect(current_user.checked_code_of_conduct).to eq(true)
expect(current_user.checked_terms_and_conditions).to eq(true)
end
# rubocop:enable RSpec/ExampleLength
end
end