~singpolyma/sgx-jmp

b0ed80e8350036164031e85e111d7c4f8b2e0896 — Amolith 1 year, 1 month ago 1e82f52
Only assign num from local inv if available

Add available_after constraint to all local inventory search queries and
update tests to match

Signed-off-by: Amolith <amolith@secluded.site>
2 files changed, 65 insertions(+), 15 deletions(-)

M lib/tel_selections.rb
M test/test_tel_selections.rb
M lib/tel_selections.rb => lib/tel_selections.rb +18 -4
@@ 324,7 324,11 @@ class TelSelections
						end

						define_method(:sql_query) do
							["SELECT * FROM tel_inventory WHERE tel LIKE ?", "+1#{@q}%"]
							[
								"SELECT * FROM tel_inventory " \
								"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
								"+1#{@q}%"
							]
						end
					}
				)


@@ 354,7 358,11 @@ class TelSelections
				end

				def sql_query
					["SELECT * FROM tel_inventory WHERE tel LIKE ?", "%#{q_digits}%"]
					[
						"SELECT * FROM tel_inventory " \
						"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
						"%#{q_digits}%"
					]
				end

				def q_digits


@@ 390,7 398,11 @@ class TelSelections
				end

				def sql_query
					["SELECT * FROM tel_inventory WHERE region = ?", @state]
					[
						"SELECT * FROM tel_inventory " \
						"WHERE available_after < LOCALTIMESTAMP AND region = ?",
						@state
					]
				end

				def to_s


@@ 438,7 450,9 @@ class TelSelections

				def sql_query
					[
						"SELECT * FROM tel_inventory WHERE region = ? AND locality = ?",
						"SELECT * FROM tel_inventory " \
						"WHERE available_after < LOCALTIMESTAMP " \
						"AND region = ? AND locality = ?",
						@state.to_s, @city
					]
				end

M test/test_tel_selections.rb => test/test_tel_selections.rb +47 -11
@@ 206,7 206,11 @@ class TelSelectionsTest < Minitest::Test
		def test_for_area_code_sql
			q = TelSelections::ChooseTel::Q.for("226")
			assert_equal(
				["SELECT * FROM tel_inventory WHERE tel LIKE ?", "+1226%"],
				[
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
					"+1226%"
				],
				q.sql_query
			)
		end


@@ 219,7 223,11 @@ class TelSelectionsTest < Minitest::Test
		def test_for_npanxx_sql
			q = TelSelections::ChooseTel::Q.for("226666")
			assert_equal(
				["SELECT * FROM tel_inventory WHERE tel LIKE ?", "+1226666%"],
				[
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
					"+1226666%"
				],
				q.sql_query
			)
		end


@@ 232,7 240,11 @@ class TelSelectionsTest < Minitest::Test
		def test_for_npanxxx_sql
			q = TelSelections::ChooseTel::Q.for("2266667")
			assert_equal(
				["SELECT * FROM tel_inventory WHERE tel LIKE ?", "+12266667%"],
				[
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
					"+12266667%"
				],
				q.sql_query
			)
		end


@@ 255,7 267,11 @@ class TelSelectionsTest < Minitest::Test
		def test_for_localvanity_sql
			q = TelSelections::ChooseTel::Q.for("~mboa")
			assert_equal(
				["SELECT * FROM tel_inventory WHERE tel LIKE ?", "%6262%"],
				[
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP AND tel LIKE ?",
					"%6262%"
				],
				q.sql_query
			)
		end


@@ 268,7 284,11 @@ class TelSelectionsTest < Minitest::Test
		def test_for_state_sql
			q = TelSelections::ChooseTel::Q.for("ON")
			assert_equal(
				["SELECT * FROM tel_inventory WHERE region = ?", "ON"],
				[
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP AND region = ?",
					"ON"
				],
				q.sql_query
			)
		end


@@ 281,7 301,11 @@ class TelSelectionsTest < Minitest::Test
		def test_for_state_name_sql
			q = TelSelections::ChooseTel::Q.for("ontario")
			assert_equal(
				["SELECT * FROM tel_inventory WHERE region = ?", "ON"],
				[
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP AND region = ?",
					"ON"
				],
				q.sql_query
			)
		end


@@ 294,7 318,11 @@ class TelSelectionsTest < Minitest::Test
		def test_for_new_york_sql
			q = TelSelections::ChooseTel::Q.for("New York")
			assert_equal(
				["SELECT * FROM tel_inventory WHERE region = ?", "NY"],
				[
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP AND region = ?",
					"NY"
				],
				q.sql_query
			)
		end


@@ 316,7 344,9 @@ class TelSelectionsTest < Minitest::Test
			)
			assert_equal(
				[
					"SELECT * FROM tel_inventory WHERE region = ? AND locality = ?",
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP " \
					"AND region = ? AND locality = ?",
					"NY", "New York City"
				],
				q.sql_query


@@ 340,7 370,9 @@ class TelSelectionsTest < Minitest::Test
			)
			assert_equal(
				[
					"SELECT * FROM tel_inventory WHERE region = ? AND locality = ?",
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP " \
					"AND region = ? AND locality = ?",
					"NY", "New York City"
				],
				q.sql_query


@@ 364,7 396,9 @@ class TelSelectionsTest < Minitest::Test
			)
			assert_equal(
				[
					"SELECT * FROM tel_inventory WHERE region = ? AND locality = ?",
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP " \
					"AND region = ? AND locality = ?",
					"ON", "Toronto"
				],
				q.sql_query


@@ 388,7 422,9 @@ class TelSelectionsTest < Minitest::Test
			)
			assert_equal(
				[
					"SELECT * FROM tel_inventory WHERE region = ? AND locality = ?",
					"SELECT * FROM tel_inventory " \
					"WHERE available_after < LOCALTIMESTAMP " \
					"AND region = ? AND locality = ?",
					"ON", "Toronto"
				],
				q.sql_query