Skip to content

Commit

Permalink
fix test without monkey patching
Browse files Browse the repository at this point in the history
  • Loading branch information
AndriyAndriyovuch committed Nov 13, 2023
1 parent 9c854d4 commit 79fefa8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby "3.2.2"

gem "mutex_m", "0.1.2"
gem "mutex_m", "0.2.0"
gem "cancancan", "~> 3.3"
gem "jbuilder", "~> 2.7"
gem "pg", "~> 1.1"
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ GEM
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
mutex_m (0.1.2)
mutex_m (0.2.0)
net-imap (0.4.4)
date
net-protocol
Expand Down Expand Up @@ -620,7 +620,7 @@ DEPENDENCIES
letter_opener
listen (~> 3.3)
mini_magick (>= 4.9.5)
mutex_m (= 0.1.2)
mutex_m (= 0.2.0)
net-smtp
omniauth (~> 1.9.1)
omniauth-facebook
Expand Down
2 changes: 0 additions & 2 deletions app/models/app_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
class AppConfig < ApplicationRecord
acts_as_singleton

public_class_method :find_by!, :all

def update_diapers_calculator(params)
self.diapers_calculator = Calculators::DiapersService.product_attributes(params)
save
Expand Down
11 changes: 4 additions & 7 deletions spec/models/app_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
require "rails_helper"

RSpec.describe AppConfig, type: :model do
fixtures :app_configs

context "is a singleton model" do
it "should not allow using new method" do
expect { AppConfig.new }.to raise_error NoMethodError
Expand All @@ -24,15 +22,14 @@
end

context "calls a service method" do
let(:app_config_instance) { app_configs(:initial_app_config) }
let(:app_config_instance) { AppConfig.instance }
let(:diapers_calculator_params) { attributes_for(:diapers_calculator_params) }
let(:updated_diapers_calculator) { attributes_for(:app_config, :updated) }

it "updates the AppConfig instances diapers calculator" do
expect do
app_config_instance.update_diapers_calculator(diapers_calculator_params)
app_config_instance.reload
end.to change(app_config_instance, :diapers_calculator).to(updated_diapers_calculator[:diapers_calculator])
app_config_instance.update_diapers_calculator(diapers_calculator_params)

expect(app_config_instance[:diapers_calculator]).to eq(updated_diapers_calculator[:diapers_calculator])
end

it "receives product attributes" do
Expand Down
10 changes: 4 additions & 6 deletions spec/requests/account/app_configs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

RSpec.describe Account::AppConfigsController, type: :request do
include_context :authorize_admin
fixtures :app_configs

describe "GET :edit" do
it "is successful" do
Expand All @@ -14,16 +13,15 @@
end

describe "PATCH #update" do
let(:app_config_instance) { app_configs(:initial_app_config) }
let(:app_config_instance) { AppConfig.instance }
let(:diapers_calculator_params) { attributes_for(:diapers_calculator_params) }
let(:updated_diapers_calculator) { attributes_for(:app_config, :updated) }

context "passed vaild params" do
before { patch account_app_config_path, params: diapers_calculator_params }

it "updates the AppConfig instances diapers calculator" do
expect do
patch account_app_config_path, params: diapers_calculator_params
app_config_instance.reload
end.to change(app_config_instance, :diapers_calculator).to(updated_diapers_calculator[:diapers_calculator])
expect(app_config_instance[:diapers_calculator]).to eq(updated_diapers_calculator[:diapers_calculator])
end
end
end
Expand Down

0 comments on commit 79fefa8

Please sign in to comment.