Виктор Ablebeam: В консоли Team.first.update(users_attributes: { id: 2 }) не работает:
2.3.1 :001 > Team.first.update(users_attributes: { id: 2 })
Team Load (0.8ms) SELECT "teams".* FROM "teams" ORDER BY "teams"."id" ASC LIMIT ? [["LIMIT", 1]]
(0.1ms) begin transaction
User Load (1.2ms) SELECT "users".* FROM "users" INNER JOIN "team_users" ON "users"."id" = "team_users"."user_id" WHERE "team_users"."team_id" = ? AND "users"."id" = 2 [["team_id", 1]]
(0.1ms) rollback transaction
ActiveRecord::RecordNotFound: Couldn't find User with ID=2 for Team with ID=1
Срабатывает только если я добавляю следующим образом:
Team.first.users << User.first
Team Load (0.4ms) SELECT "teams".* FROM "teams" ORDER BY "teams"."id" ASC LIMIT ? [["LIMIT", 1]]
User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]]
(0.1ms) begin transaction
User Exists (1.4ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER(?) AND ("users"."id" != ?) LIMIT ? [["email", "mikel@streich.co"], ["id", 1], ["LIMIT", 1]]
SQL (6.3ms) INSERT INTO "team_users" ("team_id", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["team_id", 1], ["user_id", 1], ["created_at", 2016-10-25 03:12:35 UTC], ["updated_at", 2016-10-25 03:12:35 UTC]]
(3.5ms) commit transaction
User Load (0.5ms) SELECT "users".* FROM "users" INNER JOIN "team_users" ON "users"."id" = "team_users"."user_id" WHERE "team_users"."team_id" = ? [["team_id", 1]]
И на первом и на втором скрине font-size: 1rem; разницы нет, но при этом отображаются по-разному. Здесь наверное вопрос в расширении (точнее в width) приложения.
Да, отображается ABC. Но в итоге это правильный синтаксис - писать 2-а expect внутри одного scenario? Или каждый expect нужно оборачивать в отдельный scenario?
Написано
Войдите на сайт
Чтобы задать вопрос и получить на него квалифицированный ответ.
2.3.1 :001 > Team.first.update(users_attributes: { id: 2 })
Team Load (0.8ms) SELECT "teams".* FROM "teams" ORDER BY "teams"."id" ASC LIMIT ? [["LIMIT", 1]]
(0.1ms) begin transaction
User Load (1.2ms) SELECT "users".* FROM "users" INNER JOIN "team_users" ON "users"."id" = "team_users"."user_id" WHERE "team_users"."team_id" = ? AND "users"."id" = 2 [["team_id", 1]]
(0.1ms) rollback transaction
ActiveRecord::RecordNotFound: Couldn't find User with ID=2 for Team with ID=1
Срабатывает только если я добавляю следующим образом:
Team.first.users << User.first
Team Load (0.4ms) SELECT "teams".* FROM "teams" ORDER BY "teams"."id" ASC LIMIT ? [["LIMIT", 1]]
User Load (0.6ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]]
(0.1ms) begin transaction
User Exists (1.4ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER(?) AND ("users"."id" != ?) LIMIT ? [["email", "mikel@streich.co"], ["id", 1], ["LIMIT", 1]]
SQL (6.3ms) INSERT INTO "team_users" ("team_id", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["team_id", 1], ["user_id", 1], ["created_at", 2016-10-25 03:12:35 UTC], ["updated_at", 2016-10-25 03:12:35 UTC]]
(3.5ms) commit transaction
User Load (0.5ms) SELECT "users".* FROM "users" INNER JOIN "team_users" ON "users"."id" = "team_users"."user_id" WHERE "team_users"."team_id" = ? [["team_id", 1]]