How to use destroyed method of FactoryBot.Strategy Package

Best Factory_bot_ruby code snippet using FactoryBot.Strategy.destroyed

plan_test.rb

Source:plan_test.rb Github

copy

Full Screen

...18 should_not allow_value(nil).for(:cost_aggregation_rule)19 def test_reset_contracts_counter20 assert FactoryBot.create(:simple_application_plan).reset_contracts_counter21 end22 test '#destroy does not lock if cannot be destroyed' do23 plan_one = FactoryBot.create(:application_plan)24 plan_one.expects(:can_be_destroyed?).returns(false)25 plan_one.expects(:lock!).never26 refute plan_one.destroy27 end28 test 'published returns only published plans' do29 plan_one = FactoryBot.create(:simple_application_plan)30 plan_one.publish!31 plan_two = FactoryBot.create(:simple_application_plan)32 assert_contains Plan.published, plan_one33 assert_does_not_contain Plan.published, plan_two34 end35 test 'Plan.stock returns only stock plans' do36 stock_plan = FactoryBot.create(:simple_application_plan)37 custom_plan = stock_plan.customize.save!38 assert_contains Plan.stock, stock_plan39 assert_does_not_contain Plan.stock, custom_plan40 end41 context 'customizations' do42 setup do43 @stock = FactoryBot.create(:simple_application_plan)44 @custom = @stock.customize45 @custom.save!46 end47 should 'Plan.customized should return only customized plans' do48 assert_contains Plan.customized, @custom49 assert_does_not_contain Plan.customized, @stock50 end51 should 'contain plan customizations' do52 assert @stock.customizations.to_s, [@custom].to_s53 end54 end55 test 'published plan is not losing master status when hidden' do56 service = FactoryBot.create(:simple_service)57 plan = FactoryBot.create(:simple_application_plan, :issuer => service)58 plan.publish!59 service.application_plans.default = plan60 plan.hide!61 plan.reload62 assert_equal true, plan.hidden?63 assert_equal plan, service.application_plans.default64 end65 context 'Customized Plans' do66 setup do67 @custom_account_plan = FactoryBot.create(:simple_application_plan).customize68 @custom_service_plan = FactoryBot.create(:simple_service_plan).customize69 # app plans are tested elsewhere70 @buyer = FactoryBot.create(:simple_buyer)71 end72 should 'destroy custom account plans if its single buyer is destroyed' do73 @buyer.buy! @custom_account_plan74 @buyer.destroy75 assert @buyer.destroyed?76 assert_raise ActiveRecord::RecordNotFound do77 @custom_account_plan.reload78 end79 end80 should 'destroy custom service plans if its single buyer is destroyed' do81 @buyer.buy! @custom_service_plan82 @buyer.destroy83 assert @buyer.destroyed?84 assert_raise ActiveRecord::RecordNotFound do85 @custom_service_plan.reload86 end87 end88 end89 test 'nil values' do90 plan = FactoryBot.create(:simple_plan, issuer_id: 42, issuer_type: 'Plan', type: 'Plan')91 assert plan.valid?92 plan.setup_fee = nil93 refute plan.valid?94 assert plan.errors[:setup_fee].present?95 end96 test 'default values' do97 plan = Plan.new98 assert_equal 0.0, plan.setup_fee99 assert_equal 0.0, plan.cost_per_month100 end101 context 'A Plan instance' do102 setup { @plan = FactoryBot.create(:simple_application_plan) }103 context 'in published state' do104 setup { @plan.publish! }105 should 'transition to hidden state on :hide!' do106 @plan.hide!107 assert @plan.hidden?108 end109 should 'return plan that is not published on customize' do110 custom_plan = @plan.customize111 custom_plan.save!112 refute custom_plan.published?113 end114 end115 context 'in hidden state' do116 should 'transition to published state on :publish!' do117 @plan.publish!118 assert @plan.published?119 end120 end121 should 'return false on customized?' do122 refute @plan.customized?123 end124 should 'return name on original_name' do125 assert_equal @plan.name, @plan.original_name126 end127 should 'not fail with usage_limits validating presence of plan' do128 FactoryBot.create :usage_limit, :plan => @plan129 custom = @plan.customize130 custom.save131 assert_not_equal custom.id, nil132 end133 context 'customized plan' do134 setup do135 @plan.stubs(:randomized).returns(1)136 @customized_plan = @plan.customize137 end138 should 'be saved' do139 assert !@customized_plan.new_record?140 assert_not_equal @plan, @customized_plan141 end142 should "generate randomized system_names to avoid clashes customizing several times" do143 assert_equal "#{@plan.system_name}_custom_1", @customized_plan.system_name144 @plan.stubs(:randomized).returns(2)145 @second_custom_plan = @plan.customize146 assert !@second_custom_plan.new_record? # even make sure the custom plan is saved147 assert @second_custom_plan.customized?148 assert_equal "#{@plan.system_name}_custom_2", @second_custom_plan.system_name149 end150 should 'be assigned to the same service as original plan' do151 assert_equal @plan.service, @customized_plan.service152 end153 should 'return true on customized?' do154 assert @customized_plan.customized?155 end156 should 'be assigned to original plan' do157 assert_equal @plan, @customized_plan.original158 end159 should 'append (custom) original plan name' do160 assert_equal "#{@customized_plan.original.name} (custom)", @customized_plan.name161 end162 should 'return name of original plan on original_name' do163 assert_equal @plan.name, @customized_plan.original_name164 end165 should 'be of the same class as the original' do166 %W(application_plan account_plan service_plan).each do |plan_type|167 stock = FactoryBot.create("simple_#{plan_type}".to_sym)168 stock.customize.save!169 assert stock.customizations.all? { |custom| stock.class == custom.class }170 end171 end172 context 'features' do173 %W(application_plan account_plan service_plan).each do |plan_type|174 should "be the same as of the original plan (#{plan_type})" do175 stock = FactoryBot.create("simple_#{plan_type}".to_sym)176 enabled = stock.issuer.features.create!(:name => "feature enabled",177 :scope => plan_type.camelize)178 stock.features_plans.create! :feature => enabled179 assert stock.features.reload == [enabled]180 sc = stock.customize.save!181 assert stock.customizations182 .all? { |custom| stock.features == custom.features }183 end184 end185 end186 end187 context 'copy' do188 should "create identical copy of plan with (copy) suffix in name" do189 %W(account_plan service_plan).each do |plan_type|190 stock = FactoryBot.create("simple_#{plan_type}".to_sym)191 feature = stock.issuer.features.create!(:name => "#{plan_type} feature enabled",192 :scope => plan_type.camelize)193 stock.features_plans.create! :feature => feature194 clone = stock.copy195 clone.save!196 the_different = %w{name system_name id position created_at updated_at updated_at}197 the_same = stock.attribute_names - the_different198 assert_equal stock.attributes.slice(*the_same), clone.attributes.slice(*the_same)199 assert_equal stock.features, clone.features200 assert_equal stock.name + ' (copy)', clone.name201 assert stock.system_name != clone.system_name, "System name of the cloned plan should be different"202 end203 end204 should "generate randomized system_names to avoid clashes" do205 plan = FactoryBot.build_stubbed(:simple_application_plan, system_name: 'somee_plan_foo')206 plan.stubs(:randomized).returns(1)207 copy1 = plan.copy208 assert_equal "#{plan.system_name}_copy_1", copy1.system_name209 copy1.save!210 plan.stubs(:randomized).returns(2)211 copy2 = plan.copy212 assert_equal "#{plan.system_name}_copy_2", copy2.system_name213 end214 # this is bug in aasm plugin - replace it with state_machine gem215 should_eventually "clone state" do216 stock = FactoryBot.build_stubbed(:simple_application_plan, state: 'published')217 clone = stock.copy218 clone.save!219 clone.reload220 assert_equal stock.state, clone.state221 end222 should "create identical copy of application plan with associations" do223 stock = FactoryBot.create(:simple_application_plan)224 feature = stock.issuer.features.create!(:name => "feature enabled",225 :scope => 'ApplicationPlan')226 stock.features_plans.create! :feature => feature227 metric = FactoryBot.create(:metric, :service => stock.service, :system_name => 'frags')228 stock.pricing_rules.create! :metric => metric, :min => 1, :max => 5, :cost_per_unit => 1229 ul1 = stock.usage_limits.new :period => :day, :value => 10230 ul1.metric = metric231 ul1.save!232 ul2 = stock.usage_limits.new :period => :week, :value => 50233 ul2.metric = metric234 ul2.save!235 stock.save!236 clone = stock.reload.copy237 clone.save!238 clone.reload239 attrs = stock.attribute_names - %w{name system_name id position created_at updated_at}240 assert_equal stock.attributes.slice(*attrs), clone.attributes.slice(*attrs)241 assert_equal stock.features, clone.features242 assert_equal stock.metrics, clone.metrics243 assert_equal stock.usage_limits.count, clone.usage_limits.count244 assert_equal stock.pricing_rules.count, clone.pricing_rules.count245 end246 should "create a copy even if original's plan system_name has about 220 characters" do247 # real system_name from one of our customers248 plan = FactoryBot.create(:application_plan, system_name:249 '99_mo_15kPerson_5kCompany_006Overage_copy_1427860479286288_copy_1427' \250 '8611021696677_copy_14404293909783192_copy_1443476994469875_copy_1443' \251 '5533977474842_copy_1443819978875712_copy_14460495243248389')252 copy = plan.copy253 copy.save254 assert_equal true, copy.valid?255 assert copy.errors[:system_name].blank?256 end257 end258 context 'on :aggregate_costs' do259 setup do260 @costs = [100, 200, 300]261 end262 should 'return sum of costs when cost_aggregation_rule is :sum' do263 @plan.cost_aggregation_rule = :sum264 assert_equal 600, @plan.aggregate_costs(@costs)265 end266 should 'return maximum of costs when cost_aggregation_rule is :max' do267 @plan.cost_aggregation_rule = :max268 assert_equal 300, @plan.aggregate_costs(@costs)269 end270 should 'return minimum of costs when cost_aggregation_rule is :min' do271 @plan.cost_aggregation_rule = :min272 assert_equal 100, @plan.aggregate_costs(@costs)273 end274 should 'return money' do275 cost = @plan.aggregate_costs(@costs)276 assert_respond_to cost, :amount277 assert_respond_to cost, :currency278 cost = @plan.aggregate_costs([])279 assert_respond_to cost, :amount280 assert_respond_to cost, :currency281 end282 end283 context 'on :free?' do284 context 'if cost_per_month is zero' do285 setup { @plan.cost_per_month = 0 }286 should 'return true if there are no pricing rules' do287 assert @plan.free?288 end289 should 'return true if there is no setup fee' do290 @plan.setup_fee = 0291 assert @plan.free?292 end293 should 'return false if there are some pricing rules' do294 @plan.pricing_rules.build(:max => 100, :cost_per_unit => 0.1)295 refute @plan.free?296 end297 should 'return false if there is a setup fee' do298 @plan.setup_fee = 10299 refute @plan.free?300 end301 end302 should 'return true if cost_per_month is any kind od zero' do303 @plan.cost_per_month = 0304 assert @plan.free?305 @plan.cost_per_month = 0.0306 assert @plan.free?307 @plan.cost_per_month = BigDecimal.new('0.0')308 assert @plan.free?309 end310 should 'return false if cost_per_month is greater than zero' do311 @plan.cost_per_month = 100312 refute @plan.free?313 end314 end315 should 'set cancellation period using :cancellation_period_in_days' do316 @plan.cancellation_period_in_days = 2317 assert_equal 2.days, @plan.cancellation_period318 end319 should 'accept string for cancellation_period_in_days' do320 @plan.cancellation_period_in_days = '4'321 assert_equal 4.days, @plan.cancellation_period322 end323 should 'return Money on :cost_per_month' do324 assert_instance_of ThreeScale::Money, @plan.cost_per_month325 end326 context 'on :bought_by?' do327 setup do328 @plan.cinstances.delete_all329 @buyer = FactoryBot.create(:simple_buyer)330 end331 should 'return true if there is cinstance for given user account' do332 @buyer.buy!(@plan)333 assert @plan.bought_by?(@buyer)334 end335 should 'return false if there are only deleted cinstance for given user account' do336 cinstance = @buyer.buy!(@plan)337 cinstance.destroy338 refute @plan.bought_by?(@buyer)339 end340 should 'return false for nil' do341 refute @plan.bought_by?(nil)342 end343 end344 context 'with fixed cost' do345 setup { @plan.update_attribute(:cost_per_month, 100) }346 should 'return correct values on cost_for_period' do347 assert_equal 100, @plan.cost_for_period(Time.utc(2009, 6, 1)..Time.utc(2009, 6, 1).end_of_month)348 assert_equal 50, @plan.cost_for_period(Time.utc(2009, 6, 16)..Time.utc(2009, 6, 1).end_of_month)349 cost = @plan.cost_for_period(Time.utc(2009, 6, 30)..Time.utc(2009, 6, 30).end_of_day)350 assert_in_delta 3.3, cost, 0.1351 end352 should 'round to 2 decimals' do353 assert_equal 66.67, @plan.cost_for_period(Time.utc(2009, 6, 11)..Time.utc(2009, 6, 1).end_of_month)354 end355 should 'return 0.0 if cost_per_month is zero despite of period range' do356 @plan.update_attribute(:cost_per_month, 0)357 date = Time.utc(2018, 4, 1)358 period = date..date.end_of_month359 assert_equal 0, @plan.cost_for_period(period)360 period = date..(date + 1.month).end_of_month361 assert_equal 0, @plan.cost_for_period(period)362 end363 end364 end365 test 'new plan is created in hidden state' do366 plan = FactoryBot.create(:simple_service).application_plans.build(:name => 'name')367 plan.save!368 assert_equal 'hidden', plan.state369 end370 context 'destroying a plan' do371 should "not be possible if has contract" do372 plan = FactoryBot.create(:simple_application_plan)373 cinstance = FactoryBot.create(:simple_cinstance, :plan => plan)374 plan.reload375 plan.destroy376 assert Cinstance.find_by_id(cinstance.id)377 refute plan.reload.nil?378 end379 should "not be possible if any of it's customization has contract" do380 plan = FactoryBot.create(:simple_application_plan)381 cinstance = FactoryBot.create(:simple_cinstance, :plan => plan)382 cinstance.customize_plan!383 plan.reload384 plan.destroy385 assert Cinstance.find_by_id(cinstance.id)386 refute plan.destroyed?387 end388 should "not destroy application in backend when plan cannot be destroyed" do389 plan = FactoryBot.create(:simple_application_plan)390 cinstance = FactoryBot.create(:simple_cinstance, :plan => plan)391 refute plan.can_be_destroyed?392 ThreeScale::Core::Application.expects(:delete).never393 # I don't know why this does not do the trick394 # cinstance.expects(:delete_backend_application).never395 plan.destroy396 end397 should "destroy it's usage limits" do398 plan = FactoryBot.create(:simple_application_plan)399 usage_limit = FactoryBot.create(:usage_limit, :plan => plan)400 plan.destroy401 assert_nil UsageLimit.find_by_id(usage_limit.id)402 end403 should "destroy it's pricing rules" do404 plan = FactoryBot.create(:simple_application_plan)405 pricing_rule = FactoryBot.create(:pricing_rule, :plan => plan)...

Full Screen

Full Screen

billing_test.rb

Source:billing_test.rb Github

copy

Full Screen

...34 end35 should 'return false by default' do36 assert !Account.new.credit_card_stored?37 end38 test 'unstore credit card when destroyed' do39 provider = Account.new(payment_gateway_type: :stripe, payment_gateway_options: { login: 'private_key', publishable_key: 'public_key', endpoint_secret: 'some-secret' })40 buyer = Account.new(provider_account: provider)41 buyer.payment_detail.credit_card_auth_code = 'SOMESTRING'42 ActiveMerchant::Billing::StripeGateway.any_instance.expects(:threescale_unstore).with('SOMESTRING')43 buyer.destroy44 provider = Account.new(payment_gateway_type: :braintree_blue, payment_gateway_options: {merchant_id: 'foo', public_key: 'bar', private_key: 'baz'})45 buyer = Account.new(provider_account: provider)46 buyer.payment_detail.credit_card_auth_code = 'SOMESTRING'47 ActiveMerchant::Billing::BraintreeBlueGateway.any_instance.expects(:threescale_unstore).with('SOMESTRING')48 buyer.destroy49 end50 should 'return masked credit card number on credit_card_display_number' do51 account = FactoryBot.build(:simple_account)52 account.credit_card_partial_number = '1234'53 account.save!54 assert_equal 'XXXX-XXXX-XXXX-1234', account.credit_card_display_number55 end56 should 'return nil on credit_card_display_number if credit_card_partial_number is nil' do57 account = FactoryBot.build(:simple_account)58 assert_nil account.credit_card_display_number59 end60 should 'return current year and month on credit_card_expires_on_with_default if no credit card is stored' do61 Timecop.freeze(Time.zone.local(2009, 8, 12)) do62 account = FactoryBot.build(:simple_account)63 assert_equal Date.new(2009, 8, 1), account.credit_card_expires_on_with_default64 end65 end66 should 'set credit card expiration date using year and month attributes' do67 account = FactoryBot.create(:simple_account)68 account.credit_card_expires_on_year = 202069 account.credit_card_expires_on_month = 270 account.save!71 end72 test 'accepts 2-digit year' do73 account = Account.new74 account.credit_card_expires_on_year = 2575 account.credit_card_expires_on_month = 276 assert_equal '2025-02-01', account.credit_card_expires_on.to_s77 end78 should 'return false if credit card is stored but expired' do79 account = FactoryBot.create(:simple_account, :provider_account => FactoryBot.create(:simple_provider),80 :credit_card_auth_code => '123', :credit_card_expires_on => Date.new(2009,8,12))81 assert_equal Date.new(2009, 8, 12), account.credit_card_expires_on_with_default82 end83 should 'return false if credit card is not stored' do84 account = FactoryBot.create(:simple_account)85 assert !account.credit_card_stored_and_valid?86 end87 should 'return true if credit card is stored and not expired' do88 account = FactoryBot.create(:simple_account, :provider_account => FactoryBot.create(:simple_provider),89 :credit_card_auth_code => '123', :credit_card_expires_on => Date.new(2020,8,12))90 assert account.credit_card_stored_and_valid?91 end92 should 'return true if credit card is stored and not expired' do93 account = FactoryBot.create(:simple_account, :provider_account => FactoryBot.create(:simple_provider),94 :credit_card_auth_code => '123', :credit_card_expires_on => 1000.years.from_now)95 assert account.credit_card_stored_and_valid?96 end97 should 'not take a country by default' do98 account = Account.new99 assert_nil account.billing_address_country100 assert_nil account.billing_address.country101 end102 test 'update invoices vat rate only when changed' do103 provider = FactoryBot.create(:simple_provider)104 account = FactoryBot.create(:simple_account, provider_account: provider, vat_rate: 1.0)105 invoice = account.invoices.create!(provider_account: provider,106 period: '2016-06',107 friendly_id: '2016-06-00000001')108 invoice.update_columns(vat_rate: 2.0)109 assert_equal 2.0, invoice.reload.vat_rate.to_f110 account.reload111 account.save112 assert_equal 2.0, invoice.reload.vat_rate.to_f113 account.vat_rate = 3.0114 account.save115 assert_equal 3.0, invoice.reload.vat_rate.to_f116 end117 test 'check_unresolved_invoices except for the buyers scheduled for deletion' do118 number_buyers = 2119 provider = FactoryBot.create(:simple_provider)120 FactoryBot.create_list(:simple_buyer, number_buyers, provider_account: provider)121 .each { |buyer| buyer.invoices.create!(provider_account: provider, period: '2016-06', friendly_id: '2016-06-00000001', state: 'pending') }122 assert_raise(ActiveRecord::RecordNotDestroyed) { provider.destroy! }123 refute provider.destroyed?124 provider.schedule_for_deletion!125 provider.buyers.last!.destroy!126 assert_equal number_buyers-1, provider.buyers.count127 provider.destroy!128 assert provider.destroyed?129 end130 test 'charge! sends the payment_method_id' do131 provider = FactoryBot.build(:simple_provider, payment_gateway_type: :stripe, payment_gateway_options: { login: 'sk_test_4eC39HqLyjWDarjtT1zdp7dc', publishable_key: 'pk_test_TYooMQauvdEDq54NiTphI7jx', endpoint_secret: 'some-secret' })132 buyer = FactoryBot.build(:simple_buyer, provider_account: provider)133 buyer.payment_detail.assign_attributes(credit_card_auth_code: 'cus_IhGaGqpp6zGwyd', payment_method_id: 'pm_1I5s3n2eZvKYlo2CiO193T69', credit_card_partial_number: '4242')134 PaymentTransaction.any_instance.expects(:process!).with do |_customer, _payment_gateway, opts|135 opts[:payment_method_id] == buyer.payment_detail.payment_method_id136 end137 buyer.charge!(100)138 end139end...

Full Screen

Full Screen

destroyed

Using AI Code Generation

copy

Full Screen

1 let(:user) { FactoryBot.create(:user) }2 expect(User.exists?(user.id)).to eq(false)3 let(:user) { FactoryBot.create(:user) }4 expect(User.exists?(user.id)).to eq(false)5 let(:user) { FactoryBot.create(:user) }6 expect(User.exists?(user.id)).to eq(false)7 let(:user) { FactoryBot.create(:user) }8 expect(User.exists?(user.id)).to eq(false)9 let(:user) { FactoryBot.create(:user) }10 expect(User.exists?(user.id)).to eq(false)11 let(:user) { FactoryBot.create(:user)

Full Screen

Full Screen

destroyed

Using AI Code Generation

copy

Full Screen

1 def result(evaluation)2 evaluation.notify(:after_build, result)3 evaluation.notify(:before_create, result)4 evaluation.notify(:after_create, result)5 evaluation.notify(:after_stub, result)6 def result(evaluation)7 evaluation.notify(:after_build, result)8 evaluation.notify(:before_create, result)9 evaluation.notify(:after_create, result)10 evaluation.notify(:after_stub, result)11 def result(evaluation)12 evaluation.notify(:after_build, result)13 evaluation.notify(:before_create, result)14 evaluation.notify(:after_create, result)15 evaluation.notify(:after_stub, result)16 def result(evaluation)17 evaluation.notify(:after_stub, result)18 def result(evaluation)19 evaluation.notify(:after_build, result)20 def result(evaluation)21 evaluation.notify(:after_build, result)22 def result(evaluation)23 evaluation.notify(:after_build, result)24 evaluation.notify(:before_create, result)25 evaluation.notify(:after_create, result)26 evaluation.notify(:after_stub, result)27 def result(_evaluation)28 def result(_evaluation)29 {}30 def result(_evaluation)31 def result(_evaluation)

Full Screen

Full Screen

destroyed

Using AI Code Generation

copy

Full Screen

1 def self.destroyed=(value)2 def self.create(*args)3 config.before(:suite) do4 config.before(:each) do5 config.after(:each) do6 FactoryBot::Strategy.destroyed.each(&:destroy)7 user = create(:user)8 expect(user).to be_valid9 name { 'John' }

Full Screen

Full Screen

destroyed

Using AI Code Generation

copy

Full Screen

1 def result(evaluation)2 evaluation.notify(:after_stub, self)3 def result(evaluation)4 evaluation.notify(:after_create, self)5 evaluation.notify(:after_build, self)6 def result(evaluation)7 evaluation.notify(:after_create, self)8 evaluation.notify(:after_build, self)9 def result(evaluation)10 evaluation.notify(:after_build, self)11 def result(evaluation)12 evaluation.notify(:after_build, self)13 def result(evaluation)14 evaluation.notify(:after_build, self)15 def result(evaluation)16 evaluation.notify(:after_build, self)17 evaluation.object.map(&:attributes)18 def result(evaluation)19 evaluation.notify(:after_stub, self)20 first_name { Faker::Name.first_name }21 last_name { Faker::Name.last_name }

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Factory_bot_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful