{"id":1171,"date":"2011-08-11T14:17:15","date_gmt":"2011-08-11T05:17:15","guid":{"rendered":"http:\/\/ecpplus.net\/weblog\/?p=1171"},"modified":"2020-06-15T22:05:56","modified_gmt":"2020-06-15T13:05:56","slug":"unit-test-%e3%81%ae-fixtures-%e3%81%a7%e9%96%a2%e9%80%a3%e3%81%8c%e3%81%aa%e3%81%84%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%81%ae-primary-key-%e3%82%92%e5%8f%96%e3%82%8b%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/ecpplus.net\/weblog\/unit-test-%e3%81%ae-fixtures-%e3%81%a7%e9%96%a2%e9%80%a3%e3%81%8c%e3%81%aa%e3%81%84%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%81%ae-primary-key-%e3%82%92%e5%8f%96%e3%82%8b%e6%96%b9%e6%b3%95\/","title":{"rendered":"unit test \u306e fixtures \u3067\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u3092\u53d6\u308b\u65b9\u6cd5"},"content":{"rendered":"<p>Rails \u306e unit test \u3092\u66f8\u3044\u3066\u3044\u3066\u3001\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u304c\u77e5\u308a\u305f\u3044\u72b6\u6cc1\u304c\u3042\u3063\u305f\u3002<\/p>\n<p>\u95a2\u9023\u304c\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u3060\u3068\u3001<\/p>\n<pre lang=\"ruby\">\nclass User < ActiveRecord::Base\nhas_many :posts\nend\nclass Post < ActiveRecord::Base\nbelongs_to :user\nend\n<\/pre>\n<p>\u307f\u305f\u3044\u306a\u3068\u304d\u306b<\/p>\n<p>test\/fixtures\/users.yml<\/p>\n<pre lang=\"yml\">\nchihaya:\nname: \u5343\u65e9\n<\/pre>\n<p>test\/fixtures\/posts.yml<\/p>\n<pre lang=\"yml\">\nfirst:\nuser: chihaya\ntitle: \u304f\u3063\u2026\uff01\nbody: \u5148\u65e5\u30d5\u30a7\u30b9\u304c\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u2026\n<\/pre>\n<p>\u307f\u305f\u3044\u306a\u611f\u3058\u306b\u3059\u308b\u3068\u95a2\u9023\u304c\u4f5c\u308c\u308b\u3002<\/p>\n<p>\u4eca\u56de\u306f\u3001\u5358\u7d14\u306a\u30ed\u30b0\u307f\u305f\u3044\u306a\u3082\u306e\u3067\u3001\u8272\u3093\u306a\u30c6\u30fc\u30d6\u30eb\u306e id \u3092\u3001target_id \u307f\u305f\u3044\u306a\u3068\u3053\u308d\u306b\u3057\u307e\u3063\u3066\u3001\u30af\u30e9\u30b9\u540d\u3068\u5408\u308f\u305b\u3066\u30e6\u30cb\u30fc\u30af\u306b\u306a\u308b\u3088\u3046\u306b\u7ba1\u7406\u3057\u3066\u305f\u3002\u6570\u304c\u591a\u304b\u3063\u305f\u306e\u3068\u95a2\u9023\u4ed8\u3051\u3066\u53d6\u308b\u5fc5\u8981\u304c\u7121\u304b\u3063\u305f\u306e\u3067\u3001\u95a2\u9023\u3092\u4f5c\u3063\u3066\u306a\u304b\u3063\u305f\u3093\u3060\u3051\u308c\u3069\u3082\u3001fixture \u3092\u66f8\u304f\u6642\u306b\u3001\u5916\u90e8\u306e id \u306e\u53d6\u5f97\u65b9\u6cd5\u306b\u8ff7\u3063\u305f\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u5148\u307b\u3069\u306e\u4f8b\u3067\u3001has_many, belongs_to \u304c\u7121\u304b\u3063\u305f\u6642\u306b\u3069\u3046\u3059\u308b\u304b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<br \/>\nusers.yml \u306b\u3001 id:1 \u3068\u304b\u66f8\u304f\u3068\u3044\u3046\u306e\u30821\u3064\u306e\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n<p>id \u3092\u6307\u5b9a\u305b\u305a\u306b rake fixtures:load \u3063\u3066\u3059\u308b\u3068\u3001id \u304c\u7d50\u69cb\u5927\u304d\u306a\u6570\u5b57\u306b\u306a\u308a\u307e\u3059\u304c\u3001\u3042\u308c\u306f\u30e9\u30d9\u30eb\u306e\u6587\u5b57\u5217\u306b\u3088\u3063\u3066\u8a08\u7b97\u3055\u308c\u305f\u5024\u307f\u305f\u3044\u3067\u3059\u306d\u3002<\/p>\n<p><a href=\"http:\/\/api.rubyonrails.org\/classes\/ActiveRecord\/Fixtures.html#method-c-identify\" title=\"Fixtures#identify\" target=\"_blank\" rel=\"noopener noreferrer\">ActiveRecord::Fixtures.identify(label)<\/a> \u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3067\u8a08\u7b97\u3055\u308c\u3066\u3044\u3066\u3001\u30d7\u30e9\u30c3\u30c8\u30d5\u30a9\u30fc\u30e0\u4f9d\u5b58\u3067\u3001\u540c\u3058\u6587\u5b57\u5217\u3092\u4e0e\u3048\u308c\u3070\u540c\u3058\u5024\u304c\u8fd4\u3063\u3066\u304f\u308b\u4ed5\u7d44\u307f\u306b\u306a\u3063\u3066\u3044\u308b\u3088\u3046\u3067\u3059\u3002<\/p>\n<p>\u305d\u3046\u3059\u308b\u3068\u3001\u5148\u307b\u3069\u306e\u4f8b\u3060\u3068<\/p>\n<p>test\/fixtures\/posts.yml<\/p>\n<pre lang=\"yml\">\nfirst:\nuser_id: <%= ActiveRecord::Fixtures.identify(:chihaya) %>\ntitle: \u304f\u3063\u2026\uff01\nbody: \u5148\u65e5\u30d5\u30a7\u30b9\u304c\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u2026\n<\/pre>\n<p>\u3068\u3059\u308b\u3068\u3001\u5e38\u306b\u5343\u65e9\u306e id \u304c\u53d6\u308c\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002ActiveRecord::Fixtures.identify(:chihaya) \u306e\u5024\u306f\u3001\u898b\u3066\u5206\u304b\u308b\u3088\u3046\u306b\u30c6\u30fc\u30d6\u30eb\u306b\u4f9d\u5b58\u3059\u308b\u3053\u3068\u306f\u306a\u304f\u3001\u5225\u30c6\u30fc\u30d6\u30eb\u3067 chihaya \u3068\u3044\u3046\u30e9\u30d9\u30eb\u3092\u4f7f\u3046\u3068\u3001\u540c\u3058 id \u306b\u306a\u308a\u307e\u3059\u3002ActiveRecord::Fixtures \u304c\u898b\u3064\u304b\u3089\u306a\u3044\u3068\u304d\u306f\u3001 require 'active_record\/fixtures' \u3068\u3057\u307e\u3059\u3002<\/p>\n<p>\u306a\u3093\u3060\u308d\u3046\u306a\u30fc\u3068\u601d\u3063\u3066\u305f\u5de8\u5927\u306a\u6574\u6570\u306e id \u306e\u8a08\u7b97\u65b9\u6cd5\u304c\u308f\u304b\u3063\u3066\u3059\u3063\u304d\u308a\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rails \u306e unit test \u3092\u66f8\u3044\u3066\u3044\u3066\u3001\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u304c\u77e5\u308a\u305f\u3044\u72b6\u6cc1\u304c\u3042\u3063\u305f\u3002 \u95a2\u9023\u304c\u3042\u308b\u30c6\u30fc\u30d6\u30eb\u3060\u3068\u3001 class User < ActiveRecord::Base has_ [&hellip;]\n<\/p>\n","protected":false},"author":1,"featured_media":2521,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[10,8],"class_list":["post-1171","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development","tag-rails","tag-ruby"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"Rails \u306e unit test \u3092\u66f8\u3044\u3066\u3044\u3066\u3001\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u304c\u77e5\u308a\u305f\u3044\u72b6\u6cc1\" \/>\n\t<meta name=\"robots\" content=\"max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n\t<meta name=\"author\" content=\"\u3061\u3085\u3046\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/ecpplus.net\/weblog\/unit-test-%e3%81%ae-fixtures-%e3%81%a7%e9%96%a2%e9%80%a3%e3%81%8c%e3%81%aa%e3%81%84%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%81%ae-primary-key-%e3%82%92%e5%8f%96%e3%82%8b%e6%96%b9%e6%b3%95\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"ja_JP\" \/>\n\t\t<meta property=\"og:site_name\" content=\"\u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"unit test \u306e fixtures \u3067\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u3092\u53d6\u308b\u65b9\u6cd5 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta property=\"og:description\" content=\"Rails \u306e unit test \u3092\u66f8\u3044\u3066\u3044\u3066\u3001\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u304c\u77e5\u308a\u305f\u3044\u72b6\u6cc1\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/ecpplus.net\/weblog\/unit-test-%e3%81%ae-fixtures-%e3%81%a7%e9%96%a2%e9%80%a3%e3%81%8c%e3%81%aa%e3%81%84%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%81%ae-primary-key-%e3%82%92%e5%8f%96%e3%82%8b%e6%96%b9%e6%b3%95\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\" \/>\n\t\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t\t<meta property=\"article:tag\" content=\"development\" \/>\n\t\t<meta property=\"article:tag\" content=\"rails\" \/>\n\t\t<meta property=\"article:tag\" content=\"ruby\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2011-08-11T05:17:15+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-06-15T13:05:56+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@ecpplus\" \/>\n\t\t<meta name=\"twitter:title\" content=\"unit test \u306e fixtures \u3067\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u3092\u53d6\u308b\u65b9\u6cd5 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Rails \u306e unit test \u3092\u66f8\u3044\u3066\u3044\u3066\u3001\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u304c\u77e5\u308a\u305f\u3044\u72b6\u6cc1\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@ecpplus\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"unit test \u306e fixtures \u3067\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u3092\u53d6\u308b\u65b9\u6cd5 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","description":"Rails \u306e unit test \u3092\u66f8\u3044\u3066\u3044\u3066\u3001\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u304c\u77e5\u308a\u305f\u3044\u72b6\u6cc1","canonical_url":"https:\/\/ecpplus.net\/weblog\/unit-test-%e3%81%ae-fixtures-%e3%81%a7%e9%96%a2%e9%80%a3%e3%81%8c%e3%81%aa%e3%81%84%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%81%ae-primary-key-%e3%82%92%e5%8f%96%e3%82%8b%e6%96%b9%e6%b3%95\/","robots":"max-snippet:-1, max-image-preview:large, max-video-preview:-1","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"ja_JP","og:site_name":"\u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","og:type":"article","og:title":"unit test \u306e fixtures \u3067\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u3092\u53d6\u308b\u65b9\u6cd5 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","og:description":"Rails \u306e unit test \u3092\u66f8\u3044\u3066\u3044\u3066\u3001\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u304c\u77e5\u308a\u305f\u3044\u72b6\u6cc1","og:url":"https:\/\/ecpplus.net\/weblog\/unit-test-%e3%81%ae-fixtures-%e3%81%a7%e9%96%a2%e9%80%a3%e3%81%8c%e3%81%aa%e3%81%84%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%81%ae-primary-key-%e3%82%92%e5%8f%96%e3%82%8b%e6%96%b9%e6%b3%95\/","og:image":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png","og:image:secure_url":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png","og:image:width":1920,"og:image:height":768,"article:tag":["development","rails","ruby"],"article:published_time":"2011-08-11T05:17:15+00:00","article:modified_time":"2020-06-15T13:05:56+00:00","twitter:card":"summary_large_image","twitter:site":"@ecpplus","twitter:title":"unit test \u306e fixtures \u3067\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u3092\u53d6\u308b\u65b9\u6cd5 | \u5909\u306a\u30e4\u30d0\u3044\u3082\u3093\u30ed\u30b0","twitter:description":"Rails \u306e unit test \u3092\u66f8\u3044\u3066\u3044\u3066\u3001\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u304c\u77e5\u308a\u305f\u3044\u72b6\u6cc1","twitter:creator":"@ecpplus","twitter:image":"https:\/\/ecpplus.net\/weblog\/wp-content\/uploads\/2011\/08\/ruby_on_rails.png"},"aioseo_meta_data":{"post_id":"1171","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":"","og_description":"","og_object_type":"article","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":"","og_article_tags":"","twitter_use_og":false,"twitter_card":"summary_large_image","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2021-01-02 06:34:33","updated":"2022-09-29 10:44:05","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/ecpplus.net\/weblog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/ecpplus.net\/weblog\/category\/development\/\" title=\"Development\">Development<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tunit test \u306e fixtures \u3067\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u3092\u53d6\u308b\u65b9\u6cd5\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/ecpplus.net\/weblog"},{"label":"Development","link":"https:\/\/ecpplus.net\/weblog\/category\/development\/"},{"label":"unit test \u306e fixtures \u3067\u95a2\u9023\u304c\u306a\u3044\u30c6\u30fc\u30d6\u30eb\u306e primary key \u3092\u53d6\u308b\u65b9\u6cd5","link":"https:\/\/ecpplus.net\/weblog\/unit-test-%e3%81%ae-fixtures-%e3%81%a7%e9%96%a2%e9%80%a3%e3%81%8c%e3%81%aa%e3%81%84%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%81%ae-primary-key-%e3%82%92%e5%8f%96%e3%82%8b%e6%96%b9%e6%b3%95\/"}],"_links":{"self":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/comments?post=1171"}],"version-history":[{"count":10,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1171\/revisions"}],"predecessor-version":[{"id":2531,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/posts\/1171\/revisions\/2531"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media\/2521"}],"wp:attachment":[{"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/media?parent=1171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/categories?post=1171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ecpplus.net\/weblog\/wp-json\/wp\/v2\/tags?post=1171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}