Skip to content

Commit 19e0fb9

Browse files
authored
Merge branch 'main' into copilot/follow-dplyr-120-updates
2 parents 54dacc3 + 2d7c8e0 commit 19e0fb9

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

AGENTS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ All new functions must include:
9595
## Testing
9696

9797
- Add test cases for all new functionality
98-
- Test file naming should mirror source file naming
98+
- Test file naming should mirror source file naming: `R/name.R``tests/testthat/test-name.R`
99+
- Place new tests near existing tests for the same function in the test file
100+
- Add regression tests for bug fixes directly after the last existing test for the affected function
99101
- Implement both structured and snapshot tests
100102
- When testing error behavior, prefer snapshot tests
101103
- Run tests frequently during development and at the end: `testthat::test_local(reporter = "check")`

R/foreign-keys.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,11 @@ dm_rm_fk_impl <- function(
460460
} else if (!is.null(ref_cols)) {
461461
show_disambiguation <- FALSE
462462
} else {
463-
# Check if all FKs point to the primary key
464-
show_disambiguation <- !all(map2_lgl(
465-
def$fks[idx],
466-
def$pks[idx],
463+
# Check if all FKs (being removed) point to the primary key
464+
show_disambiguation <- !all(pmap_lgl(
465+
list(def$fks[idx], idx_fk, def$pks[idx]),
467466
~ {
468-
all(map_lgl(.x$ref_column, identical, .y$column[[1]]))
467+
all(map_lgl(..1$ref_column[..2], identical, ..3$column[[1]]))
469468
}
470469
))
471470
}

tests/testthat/test-foreign-keys.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,21 @@ test_that("dm_rm_fk() works with partial matching", {
176176
})
177177

178178

179+
test_that("dm_rm_fk() produces no message when removing FK to PK in presence of FK to non-PK", {
180+
p <- tibble(p_id = 1, p2_id = 1)
181+
c1 <- tibble(p_id = 1)
182+
c2 <- tibble(p2_id = 1)
183+
184+
my_dm <-
185+
dm(p, c1, c2) %>%
186+
dm_add_pk(p, p_id) %>%
187+
dm_add_fk(c1, p_id, p) %>%
188+
dm_add_fk(c2, p2_id, p, p2_id)
189+
190+
expect_silent(my_dm %>% dm_rm_fk(c1, p_id, p))
191+
})
192+
193+
179194
test_that("dm_enum_fk_candidates() works as intended?", {
180195
skip_if_ide()
181196

0 commit comments

Comments
 (0)