From 8f8a33edd045a3865e9ec791f91f6f8388b5188e Mon Sep 17 00:00:00 2001 From: mugijiru <106833+mugijiru@users.noreply.github.com> Date: Sun, 28 Feb 2021 12:09:39 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E3=83=BC?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E3=82=92=20Rails=20=E3=81=8B=E3=82=89?= =?UTF-8?q?=E5=8F=96=E5=BE=97=E3=81=97=E3=81=A6=20inject=20=E3=81=97?= =?UTF-8?q?=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ユーザー情報を Rails から取得して session:current-user として放り込んだ上で controller に inject することで controller 等には手を入れなくても hbs で表示できるようにしている。 --- app/assets/javascripts/todo-app/templates/todo-items.hbs | 2 +- app/views/todo_items/index.html.haml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/todo-app/templates/todo-items.hbs b/app/assets/javascripts/todo-app/templates/todo-items.hbs index 27f19776..c947a844 100644 --- a/app/assets/javascripts/todo-app/templates/todo-items.hbs +++ b/app/assets/javascripts/todo-app/templates/todo-items.hbs @@ -1,4 +1,4 @@ -

TODO List

+

{{current-user.email}} さんのTODO List

{{ember-libs/button text="Create" click=(action "build")}} {{ember-libs/button text="Delete Completed Items" disabled=hiddenOrHidingCompleted isDanger=true click=(action "deleteCompletedItems")}} diff --git a/app/views/todo_items/index.html.haml b/app/views/todo_items/index.html.haml index ee70fbae..683e34c8 100644 --- a/app/views/todo_items/index.html.haml +++ b/app/views/todo_items/index.html.haml @@ -1 +1,5 @@ #todo-app + +:javascript + TodoApp.register('session:current-user', Ember.Object.extend({ email: '#{current_user.email}' })); + TodoApp.inject('controller:todo-items', 'current-user', 'session:current-user'); From 20db7dd45a8c210e4f52a3ac0a874593e712cac1 Mon Sep 17 00:00:00 2001 From: mugijiru <106833+mugijiru@users.noreply.github.com> Date: Sun, 28 Feb 2021 12:15:46 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=82=92=E5=A4=89?= =?UTF-8?q?=E6=9B=B4=E3=81=97=E3=81=9F=E3=81=AE=E3=81=A7=E3=83=86=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spec/system/todo_items_spec.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/system/todo_items_spec.rb b/spec/system/todo_items_spec.rb index e1d2a0a1..3218c4b7 100644 --- a/spec/system/todo_items_spec.rb +++ b/spec/system/todo_items_spec.rb @@ -2,10 +2,16 @@ RSpec.describe 'Todo Items', type: :system do before do - @user = create(:user) + @user = create(:user, email: 'test-user@example.com') login_as(@user) end + it 'display user email' do + visit '/todo_items' + + expect(page).to have_content 'test-user@example.com' + end + it 'display registered todo items' do create_list(:todo_item, 10, user: @user)