diff --git a/app/assets/stylesheets/microposts.css b/app/assets/stylesheets/microposts.css new file mode 100644 index 0000000..e85c297 --- /dev/null +++ b/app/assets/stylesheets/microposts.css @@ -0,0 +1,37 @@ +form#micropost_form { + display: flex; + flex-direction: column; + max-width: 55em; + + > h2 { + width: 100%; + } + + > trix-toolbar { + max-width: 95%; + } + + > trix-editor { + width: 95%; + > ul { + list-style-type: disc; + } + } + + > input[type=submit] { + width: 95%; + } +} + +.micropost { + max-width: 55em; + margin: 1em auto; + padding: .5em; + background-color: var(--inset-background-color); + border: 1px solid var(--border-color); + + > .created_at { + text-align: right; + font-size: .8em; + } +} diff --git a/app/controllers/microposts_controller.rb b/app/controllers/microposts_controller.rb new file mode 100644 index 0000000..8db1a19 --- /dev/null +++ b/app/controllers/microposts_controller.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +class MicropostsController < ApplicationController + before_action :set_micropost, only: [:show] + + def index + @microposts = helpers.current_user.microposts + end + + def new + @micropost = Micropost.new + end + + def create + micropost = Micropost.new(micropost_params) + micropost.user = helpers.current_user + if micropost.save + redirect_to micropost, notice: t(".created") + else + render :new, status: :unprocessable_entity + end + end + + def show; end + + private + + def micropost_params + params.require(:micropost).permit( + :content, + ) + end + + def set_micropost + @micropost = Micropost.find(params[:id]) + end +end diff --git a/app/models/micropost.rb b/app/models/micropost.rb index 788f81d..90e148a 100644 --- a/app/models/micropost.rb +++ b/app/models/micropost.rb @@ -5,5 +5,4 @@ class Micropost < ApplicationRecord has_rich_text :content validates :user, presence: true - validates :content, presence: true end diff --git a/app/models/user.rb b/app/models/user.rb index 0bb7824..85de9a8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,7 @@ require "securerandom" class User < ApplicationRecord has_secure_password + has_many :microposts validates :username, :first_name, diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 52ec406..2459fcf 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -1,7 +1,7 @@
-<%= t(".empty") %>
+<% else %> +Just some text
" + sign_in(users(:user)) + post microposts_url, params: { content: post_content } + assert_response :redirect + follow_redirect! + assert_includes @response.body, post_content + end +end diff --git a/test/fixtures/action_text/rich_texts.yml b/test/fixtures/action_text/rich_texts.yml index a751005..3952ef5 100644 --- a/test/fixtures/action_text/rich_texts.yml +++ b/test/fixtures/action_text/rich_texts.yml @@ -1,4 +1,4 @@ one: - record: some_text (Micropost) + record: one (Micropost) name: content body:Just some text
diff --git a/test/fixtures/microposts.yml b/test/fixtures/microposts.yml index 26c2649..4453ccd 100644 --- a/test/fixtures/microposts.yml +++ b/test/fixtures/microposts.yml @@ -1,2 +1,2 @@ -some_text: - user: gimli +one: + user: user diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 3352c8a..2329f39 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -1,3 +1,9 @@ +trevor: + username: tsvallender + password_digest: <%= BCrypt::Password.create('tolkien-abercrombie-hobb-barker', cost: 5) %> + first_name: Trevor + last_names: Vallender + email: t@tsvallender.co.uk user: username: gimli password_digest: <%= BCrypt::Password.create('tolkien-abercrombie-hobb-barker', cost: 5) %> diff --git a/test/system/new_session_test.rb b/test/system/new_session_test.rb index 5b8ccaa..0c8c7cf 100644 --- a/test/system/new_session_test.rb +++ b/test/system/new_session_test.rb @@ -8,9 +8,9 @@ class SessionsTest < ApplicationSystemTestCase visit new_session_path fill_in "username", with: user.username fill_in "password", with: "tolkien-abercrombie-hobb-barker" - click_button I18n.t("log_in") + click_button I18n.t("layouts.application.log_in") assert_text I18n.t("sessions.logged_in") - click_link I18n.t("log_out") + click_link I18n.t("layouts.application.log_out") assert_text I18n.t("sessions.logged_out") end @@ -19,7 +19,7 @@ class SessionsTest < ApplicationSystemTestCase visit new_session_path fill_in "username", with: user.username fill_in "password", with: "tolkien-abercrombie-hobb-barker" - click_button I18n.t("log_in") + click_button I18n.t("layouts.application.log_in") assert_text I18n.t("sessions.account_not_confirmed") end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 38efdc9..3d2476e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -9,3 +9,14 @@ class ActiveSupport::TestCase fixtures :all end + +class ActionDispatch::IntegrationTest + def sign_in(user) + post sessions_path, params: { + username: user.username, + password: 'tolkien-abercrombie-hobb-barker', + } + follow_redirect! + assert_includes @response.body, I18n.t("sessions.logged_in") + end +end