{"id":280961,"date":"2016-11-15T09:55:03","date_gmt":"2016-11-15T06:55:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=280961"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=280961","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0434\u0432\u0438\u0436\u043a\u0430 \u0434\u043b\u044f \u0431\u043b\u043e\u0433\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Phoenix \u0438 Elixir \/ \u0427\u0430\u0441\u0442\u044c 3. \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0440\u043e\u043b\u0435\u0439"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/edc\/f8c\/b9d\/edcf8cb9df1e4b23b636baea3538c37e.png\"\/><\/p>\n<p>  \u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u00ab<i>Elixir \u0438 Phoenix \u2014 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0443\u0434\u0430 \u0434\u0432\u0438\u0436\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430. \u0423\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0421\u0430\u0439\u0442\u044b \u0441 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\u044e, \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u044b\u0435 \u0438\u0433\u0440\u044b, \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b \u2014 \u0442\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0441\u043e\u0441\u043b\u0443\u0436\u0430\u0442 \u0445\u043e\u0440\u043e\u0448\u0443\u044e \u0441\u043b\u0443\u0436\u0431\u0443. \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0435\u0440\u0438\u0438 \u0438\u0437 11 \u0441\u0442\u0430\u0442\u0435\u0439, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0424\u0435\u043d\u0438\u043a\u0441 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0449\u0438, \u043a\u0430\u043a \u0431\u043b\u043e\u0433\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a. \u041d\u043e \u043d\u0435 \u0441\u043f\u0435\u0448\u0438\u0442\u0435 \u043a\u0443\u043a\u0441\u0438\u0442\u044c\u0441\u044f, \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0431\u0443\u0434\u044f\u0442 \u0432\u0430\u0441 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u042d\u043b\u0438\u043a\u0441\u0438\u0440 \u043b\u0438\u0431\u043e \u0441\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0440\u043e\u043b\u0435\u0439 \u0438 \u043d\u0430\u0447\u043d\u0451\u043c \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u2014 \u0437\u0434\u0435\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0443\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u0430\u043c, \u0430 \u044d\u0442\u043e \u0437\u0434\u043e\u0440\u043e\u0432\u043e! <\/p>\n<p>  <b>\u0414\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 Wunsh.ru \u0438 \u043a\u0430\u043a \u0432\u044b\u0438\u0433\u0440\u0430\u0442\u044c \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043f\u0440\u0438\u0437<\/b><\/i>\u00bb.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043e \u043d\u0430:  <\/p>\n<ul>\n<li><b>Elixir<\/b>: v1.3.1<\/li>\n<li><b>Phoenix<\/b>: v1.2.0<\/li>\n<li><b>Ecto<\/b>: v2.0.2<\/li>\n<li><b>Comeonin<\/b>: v2.5.2<\/li>\n<\/ul>\n<p>  <\/p>\n<h2>\u0413\u0434\u0435 \u043c\u044b \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438\u0441\u044c<\/h2>\n<p>  \u041c\u044b \u0440\u0430\u0441\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0441 \u0432\u0430\u043c\u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0440\u0430\u0437 \u043d\u0430 \u0442\u043e\u043c, \u0447\u0442\u043e \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u0442\u044b \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u0438 \u043d\u0430\u0447\u0430\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044e \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u043e\u0441\u0442\u0430\u043c \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0445\u0441\u044f \u0438\u0445 \u0430\u0432\u0442\u043e\u0440\u0430\u043c\u0438. \u041d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442\u044c \u0441\u043e\u0431\u043b\u044e\u0434\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u043f\u0440\u0430\u0432\u0438\u043b, \u043d\u0435 \u0434\u043e\u0436\u0438\u0434\u0430\u044f\u0441\u044c \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0435\u0433\u043e\u0434\u043d\u0438\u043a \u0443\u0434\u0430\u043b\u0438\u0442 \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043b\u0438\u0431\u043e \u0432\u0441\u0435 \u043f\u043e\u0441\u0442\u044b.<\/p>\n<p>  \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u043e\u043c: \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0440\u043e\u043b\u0438.<\/p>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0440\u043e\u043b\u0435\u0439<\/h2>\n<p>  \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0435:<\/p>\n<pre><code class=\"bash\">$ mix phoenix.gen.model Role roles name:string admin:boolean <\/code><\/pre>\n<p>  \u041a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0447\u0442\u043e-\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0435\u0435:<\/p>\n<pre><code class=\"bash\">* creating web\/models\/role.ex * creating test\/models\/role_test.exs * creating priv\/repo\/migrations\/20160721151158_create_role.exs  Remember to update your repository by running migrations: $ mix ecto.migrate <\/code><\/pre>\n<p>  \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u043e\u0432\u0435\u0442\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0438 \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>mix ecto.migrate<\/code>. \u0418\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0431\u0430\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u0434\u043e\u043b\u0436\u043d\u044b\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"bash\">Compiling 21 files (.ex)  Generated pxblog app  11:12:04.736 [info]  == Running Pxblog.Repo.Migrations.CreateRole.change\/0 forward 11:12:04.736 [info]  create table roles 11:12:04.742 [info]  == Migrated in 0.0s <\/code><\/pre>\n<p>  \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0433\u043e\u043d\u0438\u043c \u0442\u0435\u0441\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043f\u043e\u043b\u043e\u043c\u0430\u043b\u043e. \u0415\u0441\u043b\u0438 \u0432\u0441\u0435 \u043e\u043d\u0438 \u0437\u0435\u043b\u0451\u043d\u044b\u0435, \u0442\u043e \u0434\u0432\u0438\u043d\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u0438 \u0441\u0432\u044f\u0436\u0435\u043c \u0440\u043e\u043b\u0438 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<h2>\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u043e\u043b\u044f\u043c\u0438 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438<\/h2>\n<p>  \u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u0437\u0430\u043c\u044b\u0441\u0435\u043b, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u044f \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b \u043f\u0440\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u2014 \u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0440\u043e\u043b\u044c, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u0430\u044f \u0440\u043e\u043b\u044c \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442 \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0444\u0430\u0439\u043b <code>web\/models\/user.ex<\/code> \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u043d\u0438\u0436\u0435.<\/p>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0438 \u0441\u0435\u043a\u0446\u0438\u0438 \u0441\u0445\u0435\u043c\u044b <b>\u00abusers\u00bb<\/b> \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<pre><code>belongs_to :role, Pxblog.Role<\/code><\/pre>\n<p>  \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0440\u0430\u0437\u043c\u0435\u0441\u0442\u0438\u0442\u044c \u0432\u043d\u0435\u0448\u043d\u0438\u0439 \u043a\u043b\u044e\u0447 <b>role_id<\/b> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <b>users<\/b>, \u0442. \u0435. \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c, \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u00ab\u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0438\u0442\u00bb \u0440\u043e\u043b\u0438. \u0422\u0430\u043a\u0436\u0435 \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0444\u0430\u0439\u043b <code>web\/models\/role.ex<\/code> \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u0441\u0435\u043a\u0446\u0438\u044e \u0441\u0445\u0435\u043c\u044b <b>\u00abroles\u00bb<\/b> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0441\u0442\u0440\u043e\u0447\u043a\u0443: <\/p>\n<pre><code class=\"bash\">has_many :users, Pxblog.User<\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0441\u043d\u043e\u0432\u0430 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0442\u0435\u0441\u0442\u044b, \u043d\u043e \u043d\u0430 \u044d\u0442\u043e\u0442 \u0440\u0430\u0437 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043a\u0443\u0447\u0443 \u043e\u0448\u0438\u0431\u043e\u043a. \u041c\u044b \u0441\u043a\u0430\u0437\u0430\u043b\u0438 <b>Ecto<\/b>, \u0447\u0442\u043e \u043d\u0430\u0448\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u044f\u0437\u044c \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u0440\u043e\u043b\u0435\u0439, \u043d\u043e \u043d\u0438\u0433\u0434\u0435 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u044d\u0442\u043e. \u0422\u0430\u043a \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u043e\u043b\u044c \u0432 \u043f\u043e\u043b\u0435 <b>role_id<\/b>. \u0412\u044b\u0437\u043e\u0432\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<pre><code class=\"bash\">$ mix ecto.gen.migration add_role_id_to_users<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"bash\">Compiling 5 files (.ex)  * creating priv\/repo\/migrations * creating priv\/repo\/migrations\/20160721184919_add_role_id_to_users.exs <\/code><\/pre>\n<p>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0441\u0432\u0435\u0436\u0435\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043c\u0438\u0433\u0440\u0430\u0446\u0438\u0438. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043e\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code> defmodule Pxblog.Repo.Migrations.AddRoleIdToUsers do   use Ecto.Migration   def change do   end end <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432\u043d\u0435\u0441\u0442\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u0438\u0432\u043e\u0432. \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b <b>users<\/b>. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0451 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u043e\u043b\u0438 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code> alter table(:users) do   add :role_id, references(:roles) end <\/code><\/pre>\n<p>  \u041d\u0430\u043c \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0438\u043d\u0434\u0435\u043a\u0441 \u043d\u0430 \u043f\u043e\u043b\u0435 <b>role_id<\/b>:<\/p>\n<pre><code>create index(:users, [:role_id])<\/code><\/pre>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>mix ecto.migrate<\/code> \u0441\u043d\u043e\u0432\u0430. \u041c\u0438\u0433\u0440\u0430\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0439\u0442\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e! \u0415\u0441\u043b\u0438 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0442\u0435\u0441\u0442\u044b \u0442\u0435\u043f\u0435\u0440\u044c, \u0432\u0441\u0435 \u043e\u043d\u0438 \u0441\u043d\u043e\u0432\u0430 \u0431\u0443\u0434\u0443\u0442 \u0437\u0435\u043b\u0451\u043d\u044b\u043c\u0438!<\/p>\n<p>  \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0430\u0448\u0438 \u0442\u0435\u0441\u0442\u044b \u043d\u0435 \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u044b. \u041f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043c\u044b \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u044f\u043b\u0438 \u0438\u0445 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 <b>Post<\/b>\/<b>User<\/b>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0431\u044b\u0442\u044c \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c\u0438 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043f\u043e\u0441\u0442\u0430 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c. \u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0443 \u043d\u0430\u0441 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0431\u0435\u0437 \u0440\u043e\u043b\u0438. \u0418\u0437\u043c\u0435\u043d\u0438\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <b>changeset<\/b> \u0432 \u0444\u0430\u0439\u043b\u0435 <code>web\/models\/user.ex<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c (\u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 <b>:role_id<\/b> \u0432 \u0434\u0432\u0443\u0445 \u043c\u0435\u0441\u0442\u0430\u0445):<\/p>\n<pre><code> def changeset(struct, params \\\\ %{}) do     struct     |&gt; cast(params, [:username, :email, :password, :password_confirmation, :role_id])     |&gt; validate_required([:username, :email, :password, :password_confirmation, :role_id])     |&gt; hash_password end <\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0445\u0435\u043b\u043f\u0435\u0440\u0430 \u0434\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432<\/h2>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441\u0435\u0439\u0447\u0430\u0441 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043e\u0448\u0438\u0431\u043e\u043a, \u043d\u043e \u044d\u0442\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e! \u041d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0438\u0445 \u0432 \u043f\u043e\u0440\u044f\u0434\u043e\u043a. \u0418 \u043d\u0430\u0447\u043d\u0451\u043c \u043c\u044b \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0435\u043a\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0445\u0435\u043b\u043f\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0437\u0431\u0430\u0432\u0438\u0442 \u043d\u0430\u0441 \u043e\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043e\u0434\u043d\u043e\u0433\u043e \u0438 \u0442\u043e\u0433\u043e \u0436\u0435 \u043a\u043e\u0434\u0430 \u0441\u043d\u043e\u0432\u0430 \u0438 \u0441\u043d\u043e\u0432\u0430. \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0444\u0430\u0439\u043b <code>test\/support\/test_helper.ex<\/code> \u0438 \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u043c \u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<pre><code> defmodule Pxblog.TestHelper do   alias Pxblog.Repo   alias Pxblog.User   alias Pxblog.Role   alias Pxblog.Post      import Ecto, only: [build_assoc: 2]      def create_role(%{name: name, admin: admin}) do     Role.changeset(%Role{}, %{name: name, admin: admin})     |&gt; Repo.insert   end      def create_user(role, %{email: email, username: username, password: password, password_confirmation: password_confirmation}) do     role     |&gt; build_assoc(:users)     |&gt; User.changeset(%{email: email, username: username, password: password, password_confirmation: password_confirmation})     |&gt; Repo.insert   end      def create_post(user, %{title: title, body: body}) do     user     |&gt; build_assoc(:posts)     |&gt; Post.changeset(%{title: title, body: body})     |&gt; Repo.insert   end end <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0434\u0432\u0438\u043d\u0435\u043c\u0441\u044f \u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0434\u0430\u043b\u044c\u0448\u0435, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0436\u0435 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0434\u0435\u043b\u0430\u0435\u0442. \u041f\u0435\u0440\u0432\u043e\u0435, \u043d\u0430 \u0447\u0442\u043e \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u0442\u043e, \u043a\u0443\u0434\u0430 \u043c\u044b \u0435\u0433\u043e \u043f\u043e\u043b\u043e\u0436\u0438\u043b\u0438. \u0410 \u0438\u043c\u0435\u043d\u043d\u043e \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044e <b>test\/support<\/b>, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0442\u0430\u043a \u0436\u0435 \u043c\u043e\u0436\u0435\u043c \u043a\u043b\u0430\u0441\u0442\u044c \u043b\u044e\u0431\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c\u0438 \u043d\u0430\u0448\u0438\u043c \u0442\u0435\u0441\u0442\u0430\u043c \u0432 \u0446\u0435\u043b\u043e\u043c. \u041d\u0430\u043c \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u0442 \u0445\u0435\u043b\u043f\u0435\u0440 \u0438\u0437 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430, \u043d\u043e \u0442\u0430\u043a \u0438 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c!<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0430\u043b\u0438\u0430\u0441\u044b \u0434\u043b\u044f \u043c\u043e\u0434\u0443\u043b\u0435\u0439 <b>Repo<\/b>, <b>User<\/b>, <b>Role<\/b> \u0438 <b>Post<\/b>, \u0447\u0442\u043e\u0431\u044b \u0443\u043a\u043e\u0440\u043e\u0442\u0438\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u0434\u043b\u044f \u0438\u0445 \u0432\u044b\u0437\u043e\u0432\u0430. \u0417\u0430\u0442\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c <b>Ecto<\/b>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>build_assoc<\/b> \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439.<\/p>\n<p>  \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>create_role<\/b> \u043c\u044b \u043e\u0436\u0438\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0430 \u0432\u0445\u043e\u0434 \u0441\u043b\u043e\u0432\u0430\u0440\u044c, \u0432\u043a\u043b\u044e\u0447\u0430\u044e\u0449\u0438\u0439 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0440\u043e\u043b\u0438 \u0438 \u0444\u043b\u0430\u0433 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430. \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438\u0441\u044c \u0437\u0434\u0435\u0441\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>Repo.insert<\/code>, \u0437\u043d\u0430\u0447\u0438\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0430 \u0432\u044b\u0445\u043e\u0434\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 <code>{:ok, model}<\/code> \u043f\u0440\u0438 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438. \u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0441\u0442\u0430\u0432\u043a\u0430 \u0440\u0435\u0432\u0438\u0437\u0438\u0438 <b>Role<\/b>.<\/p>\n<p>  \u041c\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u043c \u0434\u0432\u0438\u0433\u0430\u0442\u044c\u0441\u044f \u043f\u043e \u0446\u0435\u043f\u043e\u0447\u043a\u0435 \u0432\u043d\u0438\u0437 \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0440\u043e\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (\u0442.\u043a. \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 <b>:users<\/b> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438), \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0440\u0435\u0432\u0438\u0437\u0438\u044e <b>User<\/b> \u0441 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u043c\u0438 \u0440\u0430\u043d\u0435\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438. \u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>Repo.insert()<\/code> \u0438 \u0432\u0441\u0451 \u0433\u043e\u0442\u043e\u0432\u043e!<\/p>\n<p>  \u0425\u043e\u0442\u044c \u0438 \u0431\u0443\u0434\u0443\u0447\u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c \u0434\u043b\u044f \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u0435\u043b\u043e \u0441 \u0441\u0443\u043f\u0435\u0440 \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u043c \u0438 \u0441\u0443\u043f\u0435\u0440 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u043e\u043b\u044c, \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u043e\u0433\u043e \u0441 \u043d\u0435\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0435\u0433\u043e \u0434\u043b\u044f \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0437\u0430\u0442\u0435\u043c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c!<\/p>\n<p>  \u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <b>create_post<\/b> \u043c\u044b \u0434\u0435\u043b\u0430\u0435\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0435 \u0432\u0435\u0449\u0438, \u0437\u0430 \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0440\u043e\u043b\u0438 \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043f\u043e\u0441\u0442\u043e\u043c \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c!<\/p>\n<h2>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u0441\u0442\u044b<\/h2>\n<p>  \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u043f\u0440\u0430\u0432\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 <code>test\/models\/user_test.exs<\/code>. \u0421\u043f\u0435\u0440\u0432\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c <code>alias Pxblog.TestHelper<\/code> \u0432 \u0441\u0430\u043c\u044b\u0439 \u0432\u0435\u0440\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0443\u043b\u044f, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0445\u0435\u043b\u043f\u0435\u0440\u044b, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u043c\u0438 \u0447\u0443\u0442\u044c \u0440\u0430\u043d\u044c\u0448\u0435. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u043b\u043e\u043a <b>setup<\/b> \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u0441\u0442\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u043e\u043b\u044c.<\/p>\n<pre><code> setup do   {:ok, role}  = TestHelper.create_role(%{name: &quot;user&quot;, admin: false})   {:ok, role: role} end <\/code><\/pre>\n<p>  \u0410 \u0437\u0430\u0442\u0435\u043c \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0436\u0435 \u0442\u0435\u0441\u0442\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c, \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0440\u043e\u043b\u044c \u0438\u0437 \u0431\u043b\u043e\u043a\u0430 <b>setup<\/b>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u043c \u0441\u0435\u0431\u0435 \u0435\u0449\u0451 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e-\u0445\u0435\u043b\u043f\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u0440\u043e\u043b\u044c\u044e:<\/p>\n<pre><code> defp valid_attrs(role) do   Map.put(@valid_attrs, :role_id, role.id) end  test &quot;changeset with valid attributes&quot;, %{role: role} do   changeset = User.changeset(%User{}, valid_attrs(role))   assert changeset.valid? end <\/code><\/pre>\n<p>  \u041f\u043e\u0434\u0432\u0435\u0434\u0451\u043c \u0438\u0442\u043e\u0433. \u041c\u044b \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u043a\u043b\u044e\u0447 <b>role<\/b>, \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c\u044b\u0439 \u0438\u0437 \u0431\u043b\u043e\u043a\u0430 <b>setup<\/b>, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c \u043a\u043b\u044e\u0447 <b>valid_attrs<\/b>, \u0447\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u043d\u0443\u044e \u0440\u043e\u043b\u044c \u0432 \u043d\u0430\u0448 \u0445\u0435\u043b\u043f\u0435\u0440! \u041a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u044d\u0442\u043e\u0442 \u0442\u0435\u0441\u0442 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0433\u043e \u0441\u043d\u043e\u0432\u0430, \u0442\u043e \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u0432\u0435\u0440\u043d\u0451\u043c\u0441\u044f \u043a \u0437\u0435\u043b\u0451\u043d\u043e\u043c\u0443 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044e \u0444\u0430\u0439\u043b\u0430 <code>test\/models\/user_test.exs<\/code>.<\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 \u0444\u0430\u0439\u043b <code>test\/controllers\/user_controller_test.exs<\/code>. \u0414\u043b\u044f \u043f\u0440\u043e\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0438\u0437 \u043d\u0435\u0433\u043e \u043c\u044b \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0442\u0435\u043c\u0438 \u0436\u0435 \u0441\u0430\u043c\u044b\u043c\u0438 \u0443\u0440\u043e\u043a\u0430\u043c\u0438. \u0412 \u0441\u0430\u043c\u044b\u0439 \u0432\u0435\u0440\u0445 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>alias Pxblog.Role<\/code>, \u0430 \u0442\u0430\u043a\u0436\u0435 <code>alias Pxblog.TestHelper<\/code> \u0441\u043b\u0435\u0434\u043e\u043c. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0431\u043b\u043e\u043a <b>setup<\/b>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u0440\u043e\u043b\u044c \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0435\u043a\u0442 <b>conn<\/b>:<\/p>\n<pre><code>setup do   {:ok, user_role}  = TestHelper.create_role(%{name: &quot;user&quot;, admin: false})   {:ok, admin_role} = TestHelper.create_role(%{name: &quot;admin&quot;, admin: true})   {:ok, conn: build_conn(), user_role: user_role, admin_role: admin_role} end<\/code><\/pre>\n<p>  \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0445\u0435\u043b\u043f\u0435\u0440 <b>valid_create_attrs<\/b>, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0439 \u0440\u043e\u043b\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u043d\u043e\u0432\u044b\u0439 \u0441\u043b\u043e\u0432\u0430\u0440\u044c \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0445 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u043c <b>role_id<\/b>.<\/p>\n<pre><code> defp valid_create_attrs(role) do   Map.put(@valid_create_attrs, :role_id, role.id) end <\/code><\/pre>\n<p>  \u041d\u0430\u043a\u043e\u043d\u0435\u0446 \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f <b>create<\/b> \u0438 <b>update<\/b> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u044d\u0442\u043e\u0442 \u0445\u0435\u043b\u043f\u0435\u0440, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <b>user_role<\/b> \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u0441\u043b\u043e\u0432\u0430\u0440\u044f.<\/p>\n<pre><code> test &quot;creates resource and redirects when data is valid&quot;, %{conn: conn, user_role: user_role} do   conn = post conn, user_path(conn, :create), user: valid_create_attrs(user_role)   assert redirected_to(conn) == user_path(conn, :index)   assert Repo.get_by(User, @valid_attrs) end  test &quot;updates chosen resource and redirects when data is valid&quot;, %{conn: conn, user_role: user_role} do   user = Repo.insert! %User{}   conn = put conn, user_path(conn, :update, user), user: valid_create_attrs(user_role)   assert redirected_to(conn) == user_path(conn, :show, user)   assert Repo.get_by(User, @valid_attrs) end <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0434\u043e\u043b\u0436\u043d\u044b \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c! \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0437\u0430\u043f\u0443\u0441\u043a <code>mix test<\/code> \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0448\u0438\u0431\u043a\u0438.<\/p>\n<h2>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u0441\u0442\u044b \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430 \u043f\u043e\u0441\u0442\u043e\u0432<\/h2>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0443 \u0441 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 <b>PostController<\/b> \u043c\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043b\u0438 \u043d\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0438 \u043a\u0443\u0447\u0438 \u0445\u0435\u043b\u043f\u0435\u0440\u043e\u0432, \u043e\u0431\u043b\u0435\u0433\u0447\u0430\u044e\u0449\u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043f\u043e\u0441\u0442\u043e\u0432 \u0441 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 \u043d\u0438\u0445 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u0440\u043e\u043b\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u0430\u043b\u0438\u0434\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 <b>Pxblog.Role<\/b> \u0432 \u0441\u0430\u043c\u044b\u0439 \u0432\u0435\u0440\u0445 \u0444\u0430\u0439\u043b\u0430 <code>test\/controllers\/post_controller_test.exs<\/code>:<\/p>\n<pre><code> alias Pxblog.Role alias Pxblog.TestHelper <\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u043b\u043e\u043a <b>setup<\/b>, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0449\u0438\u0439\u0441\u044f \u043e\u0442 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u0434\u0435\u043b\u0430\u043b\u0438 \u0440\u0430\u043d\u0435\u0435.<\/p>\n<pre><code> setup do   {:ok, role} = TestHelper.create_role(%{name: &quot;User Role&quot;, admin: false})   {:ok, user} = TestHelper.create_user(role, %{email: &quot;test@test.com&quot;, username: &quot;testuser&quot;, password: &quot;test&quot;, password_confirmation: &quot;test&quot;})   {:ok, post} = TestHelper.create_post(user, %{title: &quot;Test Post&quot;, body: &quot;Test Body&quot;})   conn = build_conn() |&gt; login_user(user)   {:ok, conn: conn, user: user, role: role, post: post} end <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0437\u0434\u0435\u0441\u044c \u0441\u0434\u0435\u043b\u0430\u043b\u0438 \u2014 \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0440\u043e\u043b\u044c \u0431\u0435\u0437 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u0432\u0435\u043b\u0435\u0433\u0438\u0439. \u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u044d\u0442\u043e\u0439 \u0440\u043e\u043b\u0438 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0417\u0430\u0442\u0435\u043c \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043f\u043e\u0441\u0442. \u041c\u044b \u0443\u0436\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u043a\u0443\u0441\u043e\u043a \u0441\u043e \u0432\u0445\u043e\u0434\u043e\u043c, \u0442\u0430\u043a \u0447\u0442\u043e \u0438\u0434\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0432\u0441\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0432\u044b\u0431\u0440\u0430\u043b \u0438\u0437 \u043d\u0438\u0445 \u0442\u0435, \u0447\u0442\u043e \u0435\u043c\u0443 \u043d\u0443\u0436\u043d\u044b.<\/p>\n<p>  \u041d\u0430\u043c \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0442\u0435\u0441\u0442, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0451 \u0441\u043d\u043e\u0432\u0430 \u0441\u0442\u0430\u043b\u043e \u0437\u0435\u043b\u0451\u043d\u044b\u043c. \u0422\u0435\u0441\u0442 <i>\u201credirects when trying to edit a post for a different user\u201d<\/i> \u043f\u0430\u0434\u0430\u0435\u0442 \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0430 \u043b\u0435\u0442\u0443 \u0435\u0449\u0451 \u043e\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0437\u043d\u0430\u044f \u043e \u0440\u043e\u043b\u0438. \u0427\u0443\u0442\u044c-\u0447\u0443\u0442\u044c \u043f\u043e\u043f\u0440\u0430\u0432\u0438\u043c \u0435\u0433\u043e:<\/p>\n<pre><code> test &quot;redirects when trying to edit a post for a different user&quot;, %{conn: conn, user: user, role: role, post: post} do   {:ok, other_user} = TestHelper.create_user(role, %{email: &quot;test2@test.com&quot;, username: &quot;test2&quot;, password: &quot;test&quot;, password_confirmation: &quot;test&quot;})   conn = get conn, user_post_path(conn, :edit, other_user, post)   assert get_flash(conn, :error) == &quot;You are not authorized to modify that post!&quot;   assert redirected_to(conn) == page_path(conn, :index)   assert conn.halted end <\/code><\/pre>\n<p>  \u0418\u0442\u0430\u043a, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u043e\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u0430, \u0430 \u0437\u0430\u0442\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 <b>other_user<\/b>, \u0447\u0442\u043e\u0431\u044b \u0438 \u0437\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f <b>TestHelper<\/b> \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u0440\u043e\u043b\u044c\u044e.<\/p>\n<p>  \u0423 \u043d\u0430\u0441 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433\u0430 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043e\u0431\u044a\u0435\u043a\u0442 <b>post<\/b> \u0438\u0437 <b>TestHelper<\/b> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b <b>build_post<\/b> \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 <b>post<\/b>, \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c. \u041f\u043e\u0441\u043b\u0435 \u0432\u0441\u0435\u0445 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0439 \u0444\u0430\u0439\u043b \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<pre><code> defmodule Pxblog.PostControllerTest do   use Pxblog.ConnCase    alias Pxblog.Post   alias Pxblog.TestHelper    @valid_attrs %{body: &quot;some content&quot;, title: &quot;some content&quot;}   @invalid_attrs %{}    setup do     {:ok, role} = TestHelper.create_role(%{name: &quot;User Role&quot;, admin: false})     {:ok, user} = TestHelper.create_user(role, %{email: &quot;test@test.com&quot;, username: &quot;testuser&quot;, password: &quot;test&quot;, password_confirmation: &quot;test&quot;})     {:ok, post} = TestHelper.create_post(user, %{title: &quot;Test Post&quot;, body: &quot;Test Body&quot;})     conn = build_conn() |&gt; login_user(user)     {:ok, conn: conn, user: user, role: role, post: post}   end    defp login_user(conn, user) do     post conn, session_path(conn, :create), user: %{username: user.username, password: user.password}   end    test &quot;lists all entries on index&quot;, %{conn: conn, user: user} do     conn = get conn, user_post_path(conn, :index, user)     assert html_response(conn, 200) =~ &quot;Listing posts&quot;   end    test &quot;renders form for new resources&quot;, %{conn: conn, user: user} do     conn = get conn, user_post_path(conn, :new, user)     assert html_response(conn, 200) =~ &quot;New post&quot;   end    test &quot;creates resource and redirects when data is valid&quot;, %{conn: conn, user: user} do     conn = post conn, user_post_path(conn, :create, user), post: @valid_attrs     assert redirected_to(conn) == user_post_path(conn, :index, user)     assert Repo.get_by(assoc(user, :posts), @valid_attrs)   end    test &quot;does not create resource and renders errors when data is invalid&quot;, %{conn: conn, user: user} do     conn = post conn, user_post_path(conn, :create, user), post: @invalid_attrs     assert html_response(conn, 200) =~ &quot;New post&quot;   end    test &quot;shows chosen resource&quot;, %{conn: conn, user: user, post: post} do     conn = get conn, user_post_path(conn, :show, user, post)     assert html_response(conn, 200) =~ &quot;Show post&quot;   end    test &quot;renders page not found when id is nonexistent&quot;, %{conn: conn, user: user} do     assert_error_sent 404, fn -&gt;       get conn, user_post_path(conn, :show, user, -1)     end   end    test &quot;renders form for editing chosen resource&quot;, %{conn: conn, user: user, post: post} do     conn = get conn, user_post_path(conn, :edit, user, post)     assert html_response(conn, 200) =~ &quot;Edit post&quot;   end    test &quot;updates chosen resource and redirects when data is valid&quot;, %{conn: conn, user: user, post: post} do     conn = put conn, user_post_path(conn, :update, user, post), post: @valid_attrs     assert redirected_to(conn) == user_post_path(conn, :show, user, post)     assert Repo.get_by(Post, @valid_attrs)   end    test &quot;does not update chosen resource and renders errors when data is invalid&quot;, %{conn: conn, user: user, post: post} do     conn = put conn, user_post_path(conn, :update, user, post), post: %{&quot;body&quot; =&gt; nil}     assert html_response(conn, 200) =~ &quot;Edit post&quot;   end    test &quot;deletes chosen resource&quot;, %{conn: conn, user: user, post: post} do     conn = delete conn, user_post_path(conn, :delete, user, post)     assert redirected_to(conn) == user_post_path(conn, :index, user)     refute Repo.get(Post, post.id)   end    test &quot;redirects when the specified user does not exist&quot;, %{conn: conn} do     conn = get conn, user_post_path(conn, :index, -1)     assert get_flash(conn, :error) == &quot;Invalid user!&quot;     assert redirected_to(conn) == page_path(conn, :index)     assert conn.halted   end    test &quot;redirects when trying to edit a post for a different user&quot;, %{conn: conn, role: role, post: post} do     {:ok, other_user} = TestHelper.create_user(role, %{email: &quot;test2@test.com&quot;, username: &quot;test2&quot;, password: &quot;test&quot;, password_confirmation: &quot;test&quot;})     conn = get conn, user_post_path(conn, :edit, other_user, post)     assert get_flash(conn, :error) == &quot;You are not authorized to modify that post!&quot;     assert redirected_to(conn) == page_path(conn, :index)     assert conn.halted   end end <\/code><\/pre>\n<h2>\u0418\u0441\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0435\u0441\u0442\u044b \u0434\u043b\u044f Session Controller<\/h2>\n<p>  \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0435\u0441\u0442\u044b \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <code>test\/controllers\/session_controller_test.exs<\/code> \u043d\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043c\u044b \u043d\u0435 \u0441\u043a\u0430\u0437\u0430\u043b\u0438 \u0438\u043c \u043d\u0430\u0447\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448 <b>TestHelper<\/b>. \u041a\u0430\u043a \u0438 \u0440\u0430\u043d\u044c\u0448\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0430\u043b\u0438\u0430\u0441\u044b \u043d\u0430\u0432\u0435\u0440\u0445 \u0444\u0430\u0439\u043b\u0430 \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u0431\u043b\u043e\u043a <b>setup<\/b>:<\/p>\n<pre><code> defmodule Pxblog.SessionControllerTest do   use Pxblog.ConnCase    alias Pxblog.User   alias Pxblog.TestHelper    setup do     {:ok, role} = TestHelper.create_role(%{name: &quot;user&quot;, admin: false})     {:ok, _user} = TestHelper.create_user(role, %{username: &quot;test&quot;, password: &quot;test&quot;, password_confirmation: &quot;test&quot;, email: &quot;test@test.com&quot;})     {:ok, conn: build_conn()}   end <\/code><\/pre>\n<p>  \u042d\u0442\u043e\u0433\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0442\u0435\u0441\u0442\u044b \u043d\u0430\u0447\u0430\u043b\u0438 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442\u044c! \u0423\u0440\u0430!<\/p>\n<h2>\u0418\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u043e\u0441\u0442\u0430\u0432\u0448\u0438\u0435\u0441\u044f \u0442\u0435\u0441\u0442\u044b<\/h2>\n<p>  \u0423 \u043d\u0430\u0441 \u043f\u043e-\u043f\u0440\u0435\u0436\u043d\u0435\u043c\u0443 \u0435\u0441\u0442\u044c \u0434\u0432\u0430 \u0441\u043b\u043e\u043c\u0430\u043d\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u0430. \u0422\u0430\u043a \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0436\u0435 \u0438\u0445 \u0437\u0435\u043b\u0451\u043d\u044b\u043c\u0438!<\/p>\n<pre><code class=\"bash\">1) test current user returns the user in the session (Pxblog.LayoutViewTest)  test\/views\/layout_view_test.exs:13  Expected truthy, got nil  code: LayoutView.current_user(conn)  stacktrace:  test\/views\/layout_view_test.exs:15  2) test current user returns nothing if there is no user in the session (Pxblog.LayoutViewTest)  test\/views\/layout_view_test.exs:18  ** (ArgumentError) cannot convert nil to param  stacktrace:  (phoenix) lib\/phoenix\/param.ex:67: Phoenix.Param.Atom.to_param\/1  (pxblog) web\/router.ex:1: Pxblog.Router.Helpers.session_path\/4  test\/views\/layout_view_test.exs:20 <\/code><\/pre>\n<p>  \u0412 \u0441\u0430\u043c\u043e\u043c \u0432\u0435\u0440\u0445\u0443 \u0444\u0430\u0439\u043b\u0430 <code>test\/views\/layout_view_test.exs<\/code> \u043c\u043e\u0436\u043d\u043e \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0451\u0442\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0431\u0435\u0437 \u0440\u043e\u043b\u0438! \u0412 \u0431\u043b\u043e\u043a\u0435 <b>setup<\/b> \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043d\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0447\u0442\u043e \u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0442\u0430\u043a\u0438\u043c \u043f\u0435\u0447\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u0441\u0442\u0432\u0438\u044f\u043c! \u0423\u0436\u0430\u0441! \u0422\u0430\u043a \u0447\u0442\u043e \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043a\u043e\u0440\u0435\u0435 \u043e\u0442\u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043c \u0432\u0435\u0441\u044c \u0444\u0430\u0439\u043b:<\/p>\n<pre><code> defmodule Pxblog.LayoutViewTest do   use Pxblog.ConnCase, async: true    alias Pxblog.LayoutView   alias Pxblog.TestHelper    setup do     {:ok, role} = TestHelper.create_role(%{name: &quot;User Role&quot;, admin: false})     {:ok, user} = TestHelper.create_user(role, %{email: &quot;test@test.com&quot;, username: &quot;testuser&quot;, password: &quot;test&quot;, password_confirmation: &quot;test&quot;})     {:ok, conn: build_conn(), user: user}   end    test &quot;current user returns the user in the session&quot;, %{conn: conn, user: user} do     conn = post conn, session_path(conn, :create), user: %{username: user.username, password: user.password}     assert LayoutView.current_user(conn)   end    test &quot;current user returns nothing if there is no user in the session&quot;, %{conn: conn, user: user} do     conn = delete conn, session_path(conn, :delete, user)     refute LayoutView.current_user(conn)   end end <\/code><\/pre>\n<p>  \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0430\u043b\u0438\u0430\u0441 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0438 <b>Role<\/b>, \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0430\u043b\u0438\u0434\u043d\u0443\u044e \u0440\u043e\u043b\u044c, \u0441\u043e\u0437\u0434\u0430\u0451\u043c \u0432\u0430\u043b\u0438\u0434\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u044d\u0442\u043e\u0439 \u0440\u043e\u043b\u044c\u044e \u0438 \u0437\u0430\u0442\u0435\u043c \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c <b>conn<\/b>. \u0418 \u0432 \u043a\u043e\u043d\u0446\u0435 \u043a\u043e\u043d\u0446\u043e\u0432 \u0432 \u043e\u0431\u0435\u0438\u0445 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u0445 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441 \u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c. \u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c <code>mix test<\/code> \u0438\u2026<br \/>  \u0412\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u0437\u0435\u043b\u0451\u043d\u044b\u0435! \u041d\u043e \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0439 (\u0442.\u043a. \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u0440\u0430\u043b\u0438\u0441\u044c \u0441 \u0437\u0430\u0431\u043e\u0442\u043e\u0439 \u043e \u0447\u0438\u0441\u0442\u043e\u043c \u043a\u043e\u0434\u0435).<\/p>\n<pre><code class=\"bash\">test\/controllers\/post_controller_test.exs:20: warning: function create_user\/0 is unused test\/views\/layout_view_test.exs:6: warning: unused alias Role test\/views\/layout_view_test.exs:5: warning: unused alias User test\/controllers\/user_controller_test.exs:5: warning: unused alias Role test\/controllers\/post_controller_test.exs:102: warning: variable user is unused test\/controllers\/post_controller_test.exs:6: warning: unused alias Role <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u0439\u0434\u0438\u0442\u0435 \u0432 \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u044d\u0442\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u0443\u0434\u0430\u043b\u0438\u0442\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043d\u044b\u0435 \u0430\u043b\u0438\u0430\u0441\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0442.\u043a. \u043e\u043d\u0438 \u043d\u0430\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b!<\/p>\n<pre><code class=\"bash\">$ mix test<\/code><\/pre>\n<p>  \u0412\u044b\u0432\u043e\u0434:<\/p>\n<pre><code class=\"bash\">......................................... Finished in 0.4 seconds 41 tests, 0 failures Randomized with seed 588307 <\/code><\/pre>\n<h2>\u0421\u043e\u0437\u0434\u0430\u0451\u043c \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430<\/h2>\n<p>  \u0412 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0441\u0447\u0451\u0442\u0435 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0442\u043e\u043b\u044c\u043a\u043e \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0443. \u041d\u043e \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f, \u043f\u0440\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u043c\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043d\u0438 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u043e\u0432. \u0412\u044b\u043b\u0435\u0447\u0438\u043c \u044d\u0442\u043e\u0442 \u043d\u0435\u0434\u0443\u0433 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 (<i>seed data<\/i>) \u0434\u043b\u044f \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0444\u0430\u0439\u043b <code>priv\/repo\/seeds.exs<\/code> \u0438 \u0432\u0441\u0442\u0430\u0432\u0438\u043c \u0432 \u043d\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code> alias Pxblog.Repo alias Pxblog.Role alias Pxblog.User  role = %Role{}   |&gt; Role.changeset(%{name: &quot;Admin Role&quot;, admin: true})   |&gt; Repo.insert! admin = %User{}   |&gt; User.changeset(%{username: &quot;admin&quot;, email: &quot;admin@test.com&quot;, password: &quot;test&quot;, password_confirmation: &quot;test&quot;, role_id: role.id})   |&gt; Repo.insert! <\/code><\/pre>\n<p>  \u0418 \u0437\u0430\u0442\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u043d\u0430\u0448\u0438 \u0441\u0438\u0434\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u044b:<\/p>\n<pre><code class=\"bash\">$ mix run priv\/repo\/seeds.exs<\/code><\/pre>\n<p>  <\/p>\n<h2>\u0427\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0434\u0430\u043b\u044c\u0448\u0435<\/h2>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0448\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0438 \u0433\u043e\u0442\u043e\u0432\u044b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441 \u0440\u043e\u043b\u044f\u043c, \u0430 \u0432\u0441\u0435 \u0442\u0435\u0441\u0442\u044b \u0441\u043d\u043e\u0432\u0430 \u0437\u0435\u043b\u0451\u043d\u044b\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0447\u0430\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440\u0430\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0434\u043b\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u0435\u0441\u043b\u0438 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0435\u0442 \u043f\u0440\u0430\u0432 \u0434\u043b\u044f \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u043f\u043e\u0441\u0442\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043a\u0430\u043a \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b, \u043a\u0430\u043a \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u044c-\u0445\u0435\u043b\u043f\u0435\u0440, \u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435, \u043a\u0430\u043a \u0443\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0442\u0435\u0441\u0442\u044b \u0437\u0435\u043b\u0451\u043d\u044b\u043c\u0438.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043e\u0442 \u0412\u0443\u043d\u0448\u0435\u0439<\/h2>\n<p>  \u0423 \u043d\u0430\u0441 \u0441\u0440\u0430\u0437\u0443 \u0434\u0432\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0435 \u043d\u043e\u0432\u043e\u0441\u0442\u0438! \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043d\u0430\u0441 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435, \u0438 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u044d\u0442\u043e\u043c\u0443 <b>\u0432\u0441\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u0438 \u0443\u0436\u0435 \u0437\u0430\u0432\u0442\u0440\u0430 \u043f\u043e\u043b\u0443\u0447\u0430\u0442 \u043d\u0430 \u043f\u043e\u0447\u0442\u0443 \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0430\u0442\u044c\u044e<\/b> (<i>\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0446\u0438\u043a\u043b\u0443<\/i>) \u043e \u0442\u043e\u043c, \u0447\u0435\u043c \u042d\u043b\u0438\u043a\u0441\u0438\u0440 \u043f\u0440\u0438\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0447\u0435\u043c\u0443 \u0438\u0445 \u0443\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442. \u0422\u0430\u043a \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u044b \u0435\u0449\u0451 \u043d\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043b\u0438\u0441\u044c, \u0442\u043e \u043d\u0435 \u0442\u0435\u0440\u044f\u0439\u0442\u0435 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 <a href=\"http:\/\/wunsh.ru\">\u0441\u043a\u043e\u0440\u0435\u0435 \u0434\u0435\u043b\u0430\u0439\u0442\u0435 \u044d\u0442\u043e<\/a>!<\/p>\n<p>  \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u043c\u044b \u0440\u0435\u0448\u0438\u043b\u0438 <b>\u0440\u0430\u0437\u044b\u0433\u0440\u0430\u0442\u044c \u0441\u0443\u043f\u0435\u0440-\u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043f\u043e\u0434\u0430\u0440\u043e\u043a \u2014 \u043a\u043d\u0438\u0433\u0443 Dave Thomas <i>\u00abProgramming Elixir\u00bb<\/i><\/b>. \u0412\u0435\u043b\u0438\u043a\u043e\u043b\u0435\u043f\u043d\u043e\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u044f\u0437\u044b\u043a (<i>\u0438 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u043e\u0432\u0438\u0447\u043a\u043e\u0432<\/i>) \u043e\u0442 \u0433\u0443\u0440\u0443 \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0435\u0439 \u043b\u0438\u0442\u0435\u0440\u0430\u0442\u0443\u0440\u044b \u043f\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e \u0414\u044d\u0439\u0432\u0430 \u0422\u043e\u043c\u0430\u0441\u0430. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0435\u0451, \u0432\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u0442 \u043d\u0430 \u0425\u0430\u0431\u0440\u0430\u0445\u0430\u0431\u0440\u0435 \u043d\u0430 \u0442\u0435\u043c\u0443 \u044f\u0437\u044b\u043a\u0430 Elixir \u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u0430 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0443\u0440\u0441\u0430 \u043e\u0442 Wunsh.ru. \u041f\u043e\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u0435\u043c \u0441\u0442\u0430\u043d\u0435\u0442 \u0447\u0435\u043b\u043e\u0432\u0435\u043a, \u0447\u044c\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u0430\u0431\u0435\u0440\u0451\u0442 \u043d\u0430\u0438\u0431\u043e\u043b\u044c\u0448\u0438\u0439 \u0440\u0435\u0439\u0442\u0438\u043d\u0433. <a href=\"http:\/\/wunsh.ru\/first_contest.html?utm_source=habr&amp;utm_medium=content&amp;utm_campaign=first_contest\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<p>  \u0423\u0441\u043f\u0435\u0445\u043e\u0432 \u0432 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0438, \u043e\u0441\u0442\u0430\u0432\u0430\u0439\u0442\u0435\u0441\u044c \u0441 \u043d\u0430\u043c\u0438!<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/315252\/\"> https:\/\/habrahabr.ru\/post\/315252\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/edc\/f8c\/b9d\/edcf8cb9df1e4b23b636baea3538c37e.png\"\/><\/p>\n<p>  \u041e\u0442 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0447\u0438\u043a\u0430: \u00ab<i>Elixir \u0438 Phoenix \u2014 \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u043e\u0433\u043e, \u043a\u0443\u0434\u0430 \u0434\u0432\u0438\u0436\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f \u0432\u0435\u0431-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430. \u0423\u0436\u0435 \u0441\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f\u043c \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0434\u043b\u044f \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439. \u0421\u0430\u0439\u0442\u044b \u0441 \u043f\u043e\u0432\u044b\u0448\u0435\u043d\u043d\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\u044e, \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u0431\u0440\u0430\u0443\u0437\u0435\u0440\u043d\u044b\u0435 \u0438\u0433\u0440\u044b, \u043c\u0438\u043a\u0440\u043e\u0441\u0435\u0440\u0432\u0438\u0441\u044b \u2014 \u0442\u0435 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 \u0441\u043e\u0441\u043b\u0443\u0436\u0430\u0442 \u0445\u043e\u0440\u043e\u0448\u0443\u044e \u0441\u043b\u0443\u0436\u0431\u0443. \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0435\u0440\u0438\u0438 \u0438\u0437 11 \u0441\u0442\u0430\u0442\u0435\u0439, \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0445 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0430 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0424\u0435\u043d\u0438\u043a\u0441 \u043a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0449\u0438, \u043a\u0430\u043a \u0431\u043b\u043e\u0433\u043e\u0432\u044b\u0439 \u0434\u0432\u0438\u0436\u043e\u043a. \u041d\u043e \u043d\u0435 \u0441\u043f\u0435\u0448\u0438\u0442\u0435 \u043a\u0443\u043a\u0441\u0438\u0442\u044c\u0441\u044f, \u0431\u0443\u0434\u0435\u0442 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0431\u0443\u0434\u044f\u0442 \u0432\u0430\u0441 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u042d\u043b\u0438\u043a\u0441\u0438\u0440 \u043b\u0438\u0431\u043e \u0441\u0442\u0430\u0442\u044c \u0435\u0433\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438.<\/p>\n<p>  \u0412 \u044d\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0440\u043e\u043b\u0435\u0439 \u0438 \u043d\u0430\u0447\u043d\u0451\u043c \u0440\u0430\u0437\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u0430. \u041a\u043b\u044e\u0447\u0435\u0432\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u2014 \u0437\u0434\u0435\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0443\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u0441\u0442\u0430\u043c, \u0430 \u044d\u0442\u043e \u0437\u0434\u043e\u0440\u043e\u0432\u043e! <\/p>\n<p>  <b>\u0414\u043e\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0434\u043e \u043a\u043e\u043d\u0446\u0430, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u0437\u0430\u0447\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 Wunsh.ru \u0438 \u043a\u0430\u043a \u0432\u044b\u0438\u0433\u0440\u0430\u0442\u044c \u043a\u0440\u0430\u0439\u043d\u0435 \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u0439 \u043f\u0440\u0438\u0437<\/b><\/i>\u00bb.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-280961","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=280961"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280961\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}