How to use run method of FactoryBot Package

Best Factory_bot_ruby code snippet using FactoryBot.run

hash_spec.rb

Source:hash_spec.rb Github

copy

Full Screen

...4 it '#mini_draft' do5 round = FactoryBot.build_stubbed(:round, mini_draft: true, deadline_time: 2.days.from_now)6 fpl_team = FactoryBot.build_stubbed(:fpl_team)7 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team, round: round)8 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)9 expect(result[:round_status]).to eq('mini_draft')10 end11 it '#waiver' do12 round = FactoryBot.build_stubbed(:round, deadline_time: 2.days.from_now)13 fpl_team = FactoryBot.build_stubbed(:fpl_team)14 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team, round: round)15 expect(Round).to receive(:first).and_return(double(Round, id: 1)).at_least(1)16 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)17 expect(result[:round_status]).to eq('waiver')18 end19 it '#trade' do20 first_round = FactoryBot.build_stubbed(:round, deadline_time: 1.week.ago)21 expect(Round).to receive(:first).and_return(first_round).at_least(1)22 round = FactoryBot.build_stubbed(:round, deadline_time: 1.day.from_now)23 fpl_team = FactoryBot.build_stubbed(:fpl_team)24 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team, round: round)25 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)26 expect(result[:round_status]).to eq('trade')27 end28 it 'has round_status of trade if the deadline time has not been passed and first round' do29 round = FactoryBot.build_stubbed(:round, deadline_time: 2.days.from_now)30 expect(Round).to receive(:first).and_return(round).at_least(1)31 fpl_team = FactoryBot.build_stubbed(:fpl_team)32 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team, round: round)33 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)34 expect(result[:round_status]).to eq('trade')35 end36 it '#pre_game' do37 round = FactoryBot.build_stubbed(:round, deadline_time: Time.now, deadline_time_game_offset: 3600)38 fpl_team = FactoryBot.build_stubbed(:fpl_team)39 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team, round: round)40 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)41 expect(result[:round_status]).to eq('pre_game')42 end43 it '#finished' do44 round = FactoryBot.build_stubbed(:round, deadline_time: 1.day.ago, data_checked: true)45 fpl_team = FactoryBot.build_stubbed(:fpl_team)46 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team, round: round)47 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)48 expect(result[:round_status]).to eq('finished')49 end50 it '#started' do51 round = FactoryBot.build_stubbed(:round, deadline_time: 1.day.ago)52 fpl_team = FactoryBot.build_stubbed(:fpl_team)53 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team, round: round)54 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)55 expect(result[:round_status]).to eq('started')56 end57 end58 context '#editable' do59 it 'is editable if the round_status is mini_draft and the user owns the fpl_team' do60 fpl_team = FactoryBot.build_stubbed(:fpl_team)61 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team)62 allow(fpl_team_list.round).to receive(:status).and_return('mini_draft')63 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)64 expect(result[:editable]).to be_truthy65 end66 it 'is editable if the round_status is waiver and the user owns the fpl_team' do67 fpl_team = FactoryBot.build_stubbed(:fpl_team)68 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team)69 allow(fpl_team_list.round).to receive(:status).and_return('waiver')70 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)71 expect(result[:editable]).to be_truthy72 end73 it 'is editable if the round_status is trade and the user owns the fpl_team' do74 fpl_team = FactoryBot.build_stubbed(:fpl_team)75 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team)76 allow(fpl_team_list.round).to receive(:status).and_return('trade')77 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)78 expect(result[:editable]).to be_truthy79 end80 it 'is not editable if the round_status is started and the user owns the fpl_team' do81 fpl_team = FactoryBot.build_stubbed(:fpl_team)82 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team)83 allow(fpl_team_list.round).to receive(:status).and_return('started')84 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)85 expect(result[:editable]).to eq('false')86 end87 it 'is not editable if the round_status is finished and the user owns the fpl_team' do88 fpl_team = FactoryBot.build_stubbed(:fpl_team)89 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team)90 allow(fpl_team_list.round).to receive(:status).and_return('finished')91 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)92 expect(result[:editable]).to eq('false')93 end94 it 'is not editable if the round_status is pre_game and the user owns the fpl_team' do95 fpl_team = FactoryBot.build_stubbed(:fpl_team)96 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team)97 allow(fpl_team_list.round).to receive(:status).and_return('pre_game')98 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)99 expect(result[:editable]).to eq('false')100 end101 it 'is not editable if the user does not own the fpl_team' do102 user = FactoryBot.build_stubbed(:user)103 fpl_team = FactoryBot.build_stubbed(:fpl_team)104 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team)105 allow(fpl_team_list.round).to receive(:status).and_return('waiver')106 result = described_class.run!(user: user, fpl_team_list: fpl_team_list)107 expect(result[:editable]).to eq('false')108 allow(fpl_team_list.round).to receive(:status).and_return('mini_draft')109 result = described_class.run!(user: user, fpl_team_list: fpl_team_list)110 expect(result[:editable]).to eq('false')111 allow(fpl_team_list.round).to receive(:status).and_return('trade')112 result = described_class.run!(user: user, fpl_team_list: fpl_team_list)113 expect(result[:editable]).to eq('false')114 end115 end116 context '#show_score' do117 it 'is true if round_status is started or finished' do118 fpl_team = FactoryBot.build_stubbed(:fpl_team)119 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team)120 allow(fpl_team_list.round).to receive(:status).and_return('started')121 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)122 expect(result[:show_score]).to be_truthy123 allow(fpl_team_list.round).to receive(:status).and_return('finished')124 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)125 expect(result[:show_score]).to be_truthy126 end127 it 'is false if round_status is not started or finished' do128 fpl_team = FactoryBot.build_stubbed(:fpl_team)129 fpl_team_list = FactoryBot.build_stubbed(:fpl_team_list, fpl_team: fpl_team)130 allow(fpl_team_list.round).to receive(:status).and_return('waiver')131 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)132 expect(result[:show_score]).to eq('false')133 allow(fpl_team_list.round).to receive(:status).and_return('trade')134 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)135 expect(result[:show_score]).to eq('false')136 allow(fpl_team_list.round).to receive(:status).and_return('mini_draft')137 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)138 expect(result[:show_score]).to eq('false')139 allow(fpl_team_list.round).to receive(:status).and_return('pre_game')140 result = described_class.run!(user: fpl_team.user, fpl_team_list: fpl_team_list)141 expect(result[:show_score]).to eq('false')142 end143 end144 context '#show_list_positions' do145 it 'home fixture, fixture started' do146 user = FactoryBot.create(:user)147 round = FactoryBot.create(:round)148 fixture = FactoryBot.create(:fixture, started: true, finished: false, round: round)149 fpl_team = FactoryBot.create(:fpl_team, user: user)150 fpl_team_list = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team, round: round)151 position = Position.find_by(singular_name_short: 'FWD')152 bps = 15153 player_fixture_histories_arr = [154 {155 minutes: 80,156 total_points: 5,157 was_home: true,158 bps: bps,159 round: round,160 fixture: fixture,161 }162 ]163 player = FactoryBot.create(164 :player,165 :player_fixture_histories,166 :"#{position.singular_name_short.downcase}",167 team: fixture.home_team,168 player_fixture_histories_arr: player_fixture_histories_arr,169 )170 list_position = FactoryBot.create(171 :list_position,172 :starting,173 player: player,174 position: position,175 fpl_team_list: fpl_team_list176 )177 role = role(list_position: list_position)178 fixture.update(stats: {179 bps: [180 { "value" => bps, "element" => player.id },181 { "value" => bps - 1, "element" => player.id + 1 },182 { "value" => bps - 2, "element" => player.id + 2 },183 ]184 })185 bonus = 3186 player_fixture_histories_arr.first[:total_points] += bonus187 params = {188 user: user,189 fpl_team_list: fpl_team_list,190 show_list_positions: true,191 }192 result = described_class.run!(params)193 hash = list_position_hash(194 player_fixture_histories_arr.first.merge(195 fpl_team_list: fpl_team_list,196 list_position: list_position,197 position: position,198 player: player,199 fixture: fixture,200 )201 )202 expect(result[:list_positions]).to contain_exactly(hash)203 expect(result.dig(:grouped_list_positions, role, position.singular_name_short)).to contain_exactly(hash)204 end205 it 'away fixture, fixture finished' do206 user = FactoryBot.create(:user)207 round = FactoryBot.create(:round)208 fixture = FactoryBot.create(:fixture, started: true, finished: true, round: round)209 fpl_team = FactoryBot.create(:fpl_team, user: user)210 fpl_team_list = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team, round: round)211 position = Position.find_by(singular_name_short: 'MID')212 bps = 15213 player_fixture_histories_arr = [214 {215 minutes: 80,216 total_points: 5,217 was_home: false,218 bps: bps,219 round: round,220 fixture: fixture,221 }222 ]223 player = FactoryBot.create(224 :player,225 :player_fixture_histories,226 :"#{position.singular_name_short.downcase}",227 team: fixture.away_team,228 player_fixture_histories_arr: player_fixture_histories_arr,229 )230 list_position = FactoryBot.create(231 :list_position,232 :starting,233 player: player,234 position: position,235 fpl_team_list: fpl_team_list236 )237 role = role(list_position: list_position)238 fixture.update(stats: {239 bps: [240 { "value" => bps, "element" => player.id },241 { "value" => bps - 1, "element" => player.id + 1 },242 { "value" => bps - 2, "element" => player.id + 2 },243 ]244 })245 params = {246 user: user,247 fpl_team_list: fpl_team_list,248 show_list_positions: true,249 }250 result = described_class.run!(params)251 hash = list_position_hash(252 player_fixture_histories_arr.first.merge(253 fpl_team_list: fpl_team_list,254 list_position: list_position,255 position: position,256 player: player,257 fixture: fixture,258 )259 )260 expect(result[:list_positions]).to contain_exactly(hash)261 expect(result.dig(:grouped_list_positions, role, position.singular_name_short)).to contain_exactly(hash)262 end263 it 'bye' do264 user = FactoryBot.create(:user)265 round = FactoryBot.create(:round)266 fpl_team = FactoryBot.create(:fpl_team, user: user)267 fpl_team_list = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team, round: round)268 list_position = FactoryBot.create(:list_position, :def, :s1, fpl_team_list: fpl_team_list)269 player = list_position.player270 position = list_position.position271 team = player.team272 role = role(list_position: list_position)273 params = {274 user: user,275 fpl_team_list: fpl_team_list,276 show_list_positions: true,277 }278 result = described_class.run!(params)279 hash = {280 "id" => list_position.id,281 "player_id" => player.id,282 "role" => role,283 "first_name" => player.first_name,284 "last_name" => player.last_name,285 "position_id" => position.id,286 "singular_name_short" => position.singular_name_short,287 "team_id" => team.id,288 "team_short_name" => team.short_name,289 "status" => "fa fa-check-circle",290 "total_points" => player.total_points,291 "fpl_team_list_id" => fpl_team_list.id,292 "team_h_id" => nil,293 "team_a_id" => nil,294 "event_points" => nil,295 "started" => nil,296 "finished" => nil,297 "finished_provisional" => nil,298 "news" => nil,299 "fixture_id" => nil,300 "round_id" => round.id,301 "opponent_short_name" => nil,302 "opponent_id" => nil,303 "team_h_difficulty" => nil,304 "team_a_difficulty" => nil,305 "minutes" => nil,306 "fixture_points" => nil,307 "home" => nil,308 "bps" => nil,309 "i" => 0,310 "fixture" => "BYE",311 }312 expect(result[:list_positions]).to contain_exactly(hash)313 expect(result.dig(:grouped_list_positions, role, position.singular_name_short)).to contain_exactly(hash)314 end315 it 'two player fixture histories in one round' do316 user = FactoryBot.create(:user)317 round = FactoryBot.create(:round)318 team = FactoryBot.create(:team)319 fixture_1 = FactoryBot.create(:fixture, started: true, finished: false, round: round, home_team: team)320 fixture_2 = FactoryBot.create(:fixture, started: true, finished: true, round: round, away_team: team)321 fpl_team = FactoryBot.create(:fpl_team, user: user)322 fpl_team_list = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team, round: round)323 position = Position.find_by(singular_name_short: 'GKP')324 bps = 15325 player_fixture_histories_arr = [326 {327 minutes: 80,328 total_points: 5,329 was_home: true,330 bps: bps,331 round: round,332 fixture: fixture_1,333 },334 {335 minutes: 80,336 total_points: 5,337 was_home: false,338 bps: bps,339 round: round,340 fixture: fixture_2,341 }342 ]343 player = FactoryBot.create(344 :player,345 :player_fixture_histories,346 :"#{position.singular_name_short.downcase}",347 team: team,348 player_fixture_histories_arr: player_fixture_histories_arr,349 )350 list_position = FactoryBot.create(351 :list_position,352 :starting,353 player: player,354 position: position,355 fpl_team_list: fpl_team_list356 )357 bonus = 2358 player_fixture_histories_arr.first[:total_points] += bonus359 role = role(list_position: list_position)360 fixture_1.update(stats: {361 bps: [362 { "value" => bps + 1, "element" => player.id + 1 },363 { "value" => bps, "element" => player.id },364 { "value" => bps - 2, "element" => player.id + 2 },365 ]366 })367 fixture_2.update(stats: {368 bps: [369 { "value" => bps + 1, "element" => player.id + 1 },370 { "value" => bps, "element" => player.id },371 { "value" => bps - 2, "element" => player.id + 2 },372 ]373 })374 params = {375 user: user,376 fpl_team_list: fpl_team_list,377 show_list_positions: true,378 }379 result = described_class.run!(params)380 hash_1 = list_position_hash(381 player_fixture_histories_arr.first.merge(382 fpl_team_list: fpl_team_list,383 list_position: list_position,384 position: position,385 player: player,386 fixture: fixture_1,387 )388 )389 hash_2 = list_position_hash(390 player_fixture_histories_arr.second.merge(391 fpl_team_list: fpl_team_list,392 list_position: list_position,393 position: position,394 player: player,395 fixture: fixture_2,396 i: 1,397 )398 )399 expect(result[:list_positions]).to contain_exactly(hash_1, hash_2)400 hash_1['fixture_points'] += hash_2['fixture_points']401 hash_1['fixture'] += ", #{hash_2['fixture']}"402 expect(result.dig(:grouped_list_positions, role, position.singular_name_short)).to contain_exactly(hash_1)403 end404 context '#show_waiver_picks' do405 it 'shows waiver picks if the user owns the fpl team' do406 user = FactoryBot.create(:user)407 fpl_team = FactoryBot.create(:fpl_team, user: user)408 fpl_team_list = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team)409 waiver_pick = FactoryBot.create(410 :waiver_pick,411 fpl_team_list: fpl_team_list,412 league: fpl_team.league,413 round: fpl_team_list.round,414 )415 params = {416 user: user,417 fpl_team_list: fpl_team_list,418 show_waiver_picks: true,419 }420 result = described_class.run!(params)421 out_player = waiver_pick.out_player422 in_player = waiver_pick.in_player423 expect(result[:waiver_picks]).to contain_exactly({424 "id" => waiver_pick.id,425 "pick_number" => waiver_pick.pick_number,426 "status" => waiver_pick.status,427 "singular_name_short" => out_player.position.singular_name_short,428 "in_player_id" => waiver_pick.in_player_id,429 "in_first_name" => in_player.first_name,430 "in_last_name" => in_player.last_name,431 "in_team_short_name" => in_player.team.short_name,432 "out_player_id" => waiver_pick.out_player_id,433 "out_first_name" => out_player.first_name,434 "out_last_name" => out_player.last_name,435 "out_team_short_name" => out_player.team.short_name,436 })437 end438 it 'does not show waiver picks if the user does not own the fpl team' do439 user = FactoryBot.create(:user)440 fpl_team = FactoryBot.create(:fpl_team)441 fpl_team_list = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team)442 FactoryBot.create(443 :waiver_pick,444 fpl_team_list: fpl_team_list,445 league: fpl_team.league,446 round: fpl_team_list.round,447 )448 params = {449 user: user,450 fpl_team_list: fpl_team_list,451 show_waiver_picks: true,452 }453 result = described_class.run!(params)454 expect(result[:waiver_picks]).to be_nil455 end456 end457 context '#show_trade_groups' do458 it 'shows all inter team trades' do459 user = FactoryBot.create(:user)460 round = FactoryBot.create(:round)461 league = FactoryBot.create(:league)462 fpl_team = FactoryBot.create(:fpl_team, user: user, league: league)463 fpl_team_list = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team, round: round)464 fpl_team_2 = FactoryBot.create(:fpl_team, league: league)465 fpl_team_list_2 = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team_2, round: round)466 player_1 = FactoryBot.create(:player)467 player_2 = FactoryBot.create(:player)468 player_3 = FactoryBot.create(:player)469 player_4 = FactoryBot.create(:player)470 fpl_team.players << player_1471 fpl_team.players << player_2472 fpl_team_2.players << player_3473 fpl_team_2.players << player_4474 out_trade_group = FactoryBot.create(475 :inter_team_trade_group,476 out_fpl_team_list: fpl_team_list,477 in_fpl_team_list: fpl_team_list_2,478 league: league,479 round: round,480 status: 'pending'481 )482 inter_team_trade_1 = FactoryBot.create(483 :inter_team_trade,484 inter_team_trade_group: out_trade_group,485 out_player: player_1,486 in_player: player_3,487 )488 in_trade_group = FactoryBot.create(489 :inter_team_trade_group,490 out_fpl_team_list: fpl_team_list_2,491 in_fpl_team_list: fpl_team_list,492 league: league,493 round: round,494 status: 'submitted',495 )496 inter_team_trade_2 = FactoryBot.create(497 :inter_team_trade,498 inter_team_trade_group: in_trade_group,499 out_player: player_4,500 in_player: player_2,501 )502 params = {503 user: user,504 fpl_team_list: fpl_team_list,505 show_trade_groups: true,506 }507 result = described_class.run!(params)508 expect(result.dig(:out_trade_groups, 'pending')).to contain_exactly(509 trade_group_hash(510 trade_group: out_trade_group,511 inter_team_trade: inter_team_trade_1,512 out_player: player_1,513 in_player: player_3,514 fpl_team: fpl_team_2,515 type: "in",516 )517 )518 expect(result.dig(:in_trade_groups, 'submitted')).to contain_exactly(519 trade_group_hash(520 trade_group: in_trade_group,521 inter_team_trade: inter_team_trade_2,522 out_player: player_4,523 in_player: player_2,524 fpl_team: fpl_team_2,525 type: "out",526 )527 )528 end529 it 'does not show in trade groups that have a pending status' do530 user = FactoryBot.create(:user)531 round = FactoryBot.create(:round)532 league = FactoryBot.create(:league)533 fpl_team = FactoryBot.create(:fpl_team, user: user, league: league)534 fpl_team_list = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team, round: round)535 fpl_team_2 = FactoryBot.create(:fpl_team, league: league)536 fpl_team_list_2 = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team_2, round: round)537 player_1 = FactoryBot.create(:player)538 player_2 = FactoryBot.create(:player)539 fpl_team.players << player_1540 fpl_team_2.players << player_2541 in_trade_group = FactoryBot.create(542 :inter_team_trade_group,543 out_fpl_team_list: fpl_team_list_2,544 in_fpl_team_list: fpl_team_list,545 league: league,546 round: round,547 status: 'pending',548 )549 FactoryBot.create(550 :inter_team_trade,551 inter_team_trade_group: in_trade_group,552 out_player: player_2,553 in_player: player_1,554 )555 params = {556 user: user,557 fpl_team_list: fpl_team_list,558 show_trade_groups: true,559 }560 result = described_class.run!(params)561 expect(result[:in_trade_groups]).to be_empty562 end563 it 'is invalid if the user does not own the fpl team' do564 user = FactoryBot.create(:user)565 fpl_team = FactoryBot.create(:fpl_team)566 fpl_team_list = FactoryBot.create(:fpl_team_list, fpl_team: fpl_team)567 params = {568 user: user,569 fpl_team_list: fpl_team_list,570 show_trade_groups: true,571 }572 outcome = described_class.run(params)573 expect(outcome).not_to be_valid574 end575 end576 end577 private578 def list_position_hash(579 fpl_team_list:,580 list_position:,581 position:,582 round:,583 player:,584 fixture:,585 minutes:,586 total_points:,...

Full Screen

Full Screen

update_spec.rb

Source:update_spec.rb Github

copy

Full Screen

...4 league = FactoryBot.create(:league, status: 'draft')5 fpl_team = FactoryBot.create(:fpl_team, league: league)6 draft_pick = FactoryBot.create(:draft_pick, fpl_team: fpl_team, league: league)7 player = FactoryBot.create(:player)8 expect_to_run(9 Leagues::Activate,10 with: { league: league },11 )12 expect_to_delay_run(13 DraftPicks::Broadcast,14 with: {15 league: league,16 user: draft_pick.user,17 player: player,18 mini_draft: false,19 },20 )21 described_class.run!(league: league, draft_pick: draft_pick, user: draft_pick.user, player: player)22 expect(draft_pick.player).to eq(player)23 expect(fpl_team.players).to contain_exactly(player)24 expect(league.players).to contain_exactly(player)25 end26 it 'with a mini draft pick' do27 league = FactoryBot.create(:league, status: 'draft')28 fpl_team = FactoryBot.create(:fpl_team, league: league)29 mini_draft = true30 draft_pick = FactoryBot.create(:draft_pick, fpl_team: fpl_team, league: league)31 expect_to_run(32 Leagues::Activate,33 with: { league: league },34 )35 expect_to_delay_run(36 DraftPicks::Broadcast,37 with: {38 league: league,39 user: draft_pick.user,40 player: nil,41 mini_draft: mini_draft,42 },43 )44 described_class.run!(league: league, draft_pick: draft_pick, user: draft_pick.user, mini_draft: mini_draft)45 expect(draft_pick.mini_draft).to eq(mini_draft)46 end47 it '#authorised_user' do48 league = FactoryBot.build_stubbed(:league, status: 'draft')49 fpl_team = FactoryBot.build_stubbed(:fpl_team, league: league)50 draft_pick = FactoryBot.build_stubbed(:draft_pick, fpl_team: fpl_team, league: league)51 user = FactoryBot.build_stubbed(:user)52 player = FactoryBot.build_stubbed(:player)53 expect(league.decorate).to receive(:current_draft_pick).and_return(draft_pick)54 outcome = described_class.run(league: league, draft_pick: draft_pick, user: user, player: player)55 expect(outcome.errors.full_messages).to contain_exactly("You are not authorised to update this draft pick.")56 end57 it '#draft_pick_current' do58 league = FactoryBot.build_stubbed(:league, status: 'draft')59 fpl_team = FactoryBot.build_stubbed(:fpl_team, league: league)60 draft_pick = FactoryBot.build_stubbed(:draft_pick, fpl_team: fpl_team, league: league)61 player = FactoryBot.build_stubbed(:player)62 expect(league.decorate).to receive(:current_draft_pick).and_return(double(DraftPick))63 outcome = described_class.run(league: league, draft_pick: draft_pick, user: fpl_team.user, player: player)64 expect(outcome.errors.full_messages).to contain_exactly("You cannot pick out of turn.")65 end66 it '#player_unpicked - league' do67 league = FactoryBot.build_stubbed(:league, status: 'draft')68 fpl_team = FactoryBot.build_stubbed(:fpl_team, league: league)69 draft_pick = FactoryBot.build_stubbed(:draft_pick, fpl_team: fpl_team, league: league)70 player = FactoryBot.build_stubbed(:player)71 expect(league.decorate).to receive(:current_draft_pick).and_return(draft_pick)72 expect(league).to receive(:players).and_return([player])73 outcome = described_class.run(league: league, draft_pick: draft_pick, user: fpl_team.user, player: player)74 expect(outcome.errors.full_messages)75 .to contain_exactly("#{player.decorate.name} is has already been picked by another fpl team in your league.")76 end77 it '#player_unpicked - fpl_team' do78 league = FactoryBot.build_stubbed(:league, status: 'draft')79 fpl_team = FactoryBot.build_stubbed(:fpl_team, league: league)80 draft_pick = FactoryBot.build_stubbed(:draft_pick, fpl_team: fpl_team, league: league)81 player = FactoryBot.build_stubbed(:player)82 expect(league.decorate).to receive(:current_draft_pick).and_return(draft_pick)83 expect(fpl_team.players).to receive(:include?).and_return(true)84 outcome = described_class.run(league: league, draft_pick: draft_pick, user: fpl_team.user, player: player)85 expect(outcome.errors.full_messages)86 .to contain_exactly("#{player.decorate.name} is already in your fpl team.")87 end88 it '#mini_draft_picked' do89 league = FactoryBot.build_stubbed(:league, status: 'draft')90 fpl_team = FactoryBot.build_stubbed(:fpl_team, league: league)91 expect(fpl_team.decorate).to receive(:mini_draft_picked?).and_return(true)92 draft_pick = FactoryBot.build_stubbed(:draft_pick, fpl_team: fpl_team, league: league)93 expect(league.decorate).to receive(:current_draft_pick).and_return(draft_pick)94 outcome = described_class.run(league: league, draft_pick: draft_pick, user: fpl_team.user, mini_draft: true)95 expect(outcome.errors.full_messages)96 .to contain_exactly("You have already selected your position in the mini draft.")97 end98 it '#all_players_picked' do99 league = FactoryBot.build_stubbed(:league, status: 'draft')100 fpl_team = FactoryBot.build_stubbed(:fpl_team, league: league)101 draft_pick = FactoryBot.build_stubbed(:draft_pick, fpl_team: fpl_team, league: league)102 expect(fpl_team.decorate).to receive(:all_players_picked?).and_return(true)103 expect(league.decorate).to receive(:current_draft_pick).and_return(draft_pick)104 player = FactoryBot.build_stubbed(:player)105 outcome = described_class.run(league: league, draft_pick: draft_pick, user: fpl_team.user, player: player)106 expect(outcome.errors.full_messages)107 .to contain_exactly("You are only allowed #{FplTeam::QUOTAS[:players]} players in a team.")108 end109 it '#maximum_number_of_players_by_position' do110 league = FactoryBot.build_stubbed(:league, status: 'draft')111 fpl_team = FactoryBot.build_stubbed(:fpl_team, league: league)112 draft_pick = FactoryBot.build_stubbed(:draft_pick, fpl_team: fpl_team, league: league)113 expect(league.decorate).to receive(:current_draft_pick).and_return(draft_pick)114 quota = FplTeam::QUOTAS[:forwards]115 quota.times { fpl_team.players << FactoryBot.create(:player, :fwd) }116 player = FactoryBot.build_stubbed(:player, :fwd)117 outcome = described_class.run(league: league, draft_pick: draft_pick, user: fpl_team.user, player: player)118 expect(outcome.errors.full_messages).to contain_exactly("You can't have more than #{quota} forwards in your team.")119 end120 it '#maximum_number_of_players_from_team' do121 league = FactoryBot.build_stubbed(:league, status: 'draft')122 fpl_team = FactoryBot.build_stubbed(:fpl_team, league: league)123 draft_pick = FactoryBot.build_stubbed(:draft_pick, fpl_team: fpl_team, league: league)124 expect(league.decorate).to receive(:current_draft_pick).and_return(draft_pick)125 team = FactoryBot.create(:team)126 quota = FplTeam::QUOTAS[:team]127 quota.times { fpl_team.players << FactoryBot.create(:player, team: team) }128 player = FactoryBot.build_stubbed(:player, :gkp, team: team)129 outcome = described_class.run(league: league, draft_pick: draft_pick, user: fpl_team.user, player: player)130 expect(outcome.errors.full_messages)131 .to contain_exactly("You can't have more than #{quota} players from the same team (#{team.name}).")132 end133 it '#league_status' do134 league = FactoryBot.build_stubbed(:league, status: 'active')135 fpl_team = FactoryBot.build_stubbed(:fpl_team, league: league)136 draft_pick = FactoryBot.build_stubbed(:draft_pick, fpl_team: fpl_team, league: league)137 expect(league.decorate).to receive(:current_draft_pick).and_return(draft_pick)138 player = FactoryBot.build_stubbed(:player)139 outcome = described_class.run(league: league, draft_pick: draft_pick, user: fpl_team.user, player: player)140 expect(outcome.errors.full_messages).to contain_exactly("You cannot draft players at this time.")141 end142end...

Full Screen

Full Screen

default.rb

Source:default.rb Github

copy

Full Screen

2 module Syntax3 module Default4 include Methods5 def define(&block)6 DSL.run(block)7 end8 def modify(&block)9 ModifyDSL.run(block)10 end11 class DSL12 def factory(name, options = {}, &block)13 factory = Factory.new(name, options)14 proxy = FactoryBot::DefinitionProxy.new(factory.definition)15 proxy.instance_eval(&block) if block_given?16 FactoryBot.register_factory(factory)17 proxy.child_factories.each do |(child_name, child_options, child_block)|18 parent_factory = child_options.delete(:parent) || name19 factory(child_name, child_options.merge(parent: parent_factory), &child_block)20 end21 end22 def sequence(name, *args, &block)23 FactoryBot.register_sequence(Sequence.new(name, *args, &block))24 end25 def trait(name, &block)26 FactoryBot.register_trait(Trait.new(name, &block))27 end28 def to_create(&block)29 FactoryBot.to_create(&block)30 end31 def skip_create32 FactoryBot.skip_create33 end34 def initialize_with(&block)35 FactoryBot.initialize_with(&block)36 end37 def self.run(block)38 new.instance_eval(&block)39 end40 delegate :before, :after, :callback, to: :configuration41 private42 def configuration43 FactoryBot.configuration44 end45 end46 class ModifyDSL47 def factory(name, options = {}, &block)48 factory = FactoryBot.factory_by_name(name)49 proxy = FactoryBot::DefinitionProxy.new(factory.definition.overridable)50 proxy.instance_eval(&block)51 end52 def self.run(block)53 new.instance_eval(&block)54 end55 end56 end57 end58 extend Syntax::Default59end...

Full Screen

Full Screen

run

Using AI Code Generation

copy

Full Screen

1 FactoryBot.create(:user)2 FactoryBot.create(:user)3 FactoryBot.create(:user)4 FactoryBot.create(:user)5 FactoryBot.create(:user)6 FactoryBot.create(:user)7 FactoryBot.create(:user)8 FactoryBot.create(:user)

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.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful