-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial commit for Daily Nerd, fixes #88 * working db changes, form, policy * lint * add validation * update daily nerd counter * make message field required * correct fixture, and method name * add specs * add comment * update comment * update readme * create feedback on demand * Update app/policies/daily_nerd_message_policy.rb Co-authored-by: Maximilian Langenbeck <[email protected]> * address feedback * back to locals * Add a little UX --------- Co-authored-by: Maximilian Langenbeck <[email protected]> Co-authored-by: Daniel Diekmeier <[email protected]>
- Loading branch information
1 parent
2567ebd
commit 22d96e2
Showing
28 changed files
with
287 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
class DailyNerdMessagesController < ApplicationController | ||
before_action :authenticate_user! | ||
before_action :assign_daily_nerd_message, only: [:update] | ||
|
||
def create | ||
@daily_nerd_message = authorize DailyNerdMessage.new(daily_nerd_message_attributes.merge(sprint_feedback:)) | ||
if @daily_nerd_message.save | ||
SlackPostDailyNerdJob.perform_later(daily_nerd_message: @daily_nerd_message) | ||
sprint_feedback.add_daily_nerd_entry(@daily_nerd_message.created_at) | ||
redirect_to sprints_path | ||
else | ||
render "new", status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def update | ||
@daily_nerd_message.update!(daily_nerd_message_attributes) | ||
redirect_to sprints_path | ||
end | ||
|
||
private | ||
|
||
def daily_nerd_message_attributes | ||
params.require(:daily_nerd_message).permit(:message) | ||
end | ||
|
||
def assign_daily_nerd_message | ||
@daily_nerd_message = authorize DailyNerdMessage.find(params[:id]) | ||
end | ||
|
||
def sprint_feedback | ||
@sprint_feedback ||= current_user.sprint_feedbacks.find_by(sprint: Sprint.current.take) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class SlackPostDailyNerdJob < ApplicationJob | ||
queue_as :notification | ||
sidekiq_options retry: 0 | ||
|
||
def perform(daily_nerd_message:) | ||
daily_nerd_message.post_to_slack | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: daily_nerd_messages | ||
# | ||
# id :uuid not null, primary key | ||
# sprint_feedback_id :uuid not null | ||
# message :string | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
class DailyNerdMessage < ApplicationRecord | ||
belongs_to :sprint_feedback | ||
|
||
validates :message, presence: true | ||
|
||
def post_to_slack | ||
User::SlackNotification.new(sprint_feedback.user).post_daily_nerd_message(message) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class DailyNerdMessagePolicy < ApplicationPolicy | ||
def home? | ||
hr? || users_own_message? | ||
end | ||
|
||
def create? | ||
hr? || users_own_message? | ||
end | ||
|
||
def update? | ||
hr? || users_own_message? | ||
end | ||
|
||
def users_own_message? | ||
user.id == record.sprint_feedback.user_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
= form_with model: daily_nerd_message, class: :stack, builder: AwesomeForm do |f| | ||
= f.input :message, as: :text, placeholder: t(".message_placeholder"), required: true, additional_class: "input__input--daily-nerd" | ||
span = f.submit class: :button, data: { turbo_submits_with: t('.submits_with') } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= render partial: "form", locals: {daily_nerd_message: @daily_nerd_message} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
= render partial: "form", locals: {daily_nerd_message: @daily_nerd_message} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8g0slLgy60K8tQLudFHNQKKy1hHtKlHA9ltjc45wVSN7qrB+qufXavh6szdM3NMUPC8C9V8jKnC8+fYG8YBGiNGIAUubccFtaITGUGxCQQ6hnrxZMVe+fIaXBoY3zxnGbpML/O+EEoD9ULnHJU+o/3Gzpd/QkEFEwK8f3bJGBJTkMkVo6NzEP6WF0e3p7G3NYaRxVTClkz2DZ/2DLuv/wXJ+8oTrGy7+0+nzYRkZoPQ/RNnSTn25uHlX1ssz0UNtqUQ4u0QhlMPb4yph1GXJSo4gFWfaxNGlDOctP5CDuswF+rdQXfop7a98uFV9uxz/vP87LGs39550R5+I6bPtPpKQedEBZQLOnE82C/TAiKxJJgrGCmmijkSK7p3Ie0WauYdAFonbzv+Jt4ckvmUCqYu3S59Vd+T9UKQ8Q3VKn7bMN2WAFDln/lOT+UFgZ/AfOwkzLGQ8vikC7syzEXsZlnngmlMzbOWznYN6z085ZulbSnxZhTYu+pKCP+VsvuHi/2kMxv+5J4CMezmFQqLTLCfJ24TJIlcKUPe3LEAAilHLm73jMmy6t86RZgq6BUkaBjxOKp/HNMq4ySScMNwyMe9bdcTDJSZro8smM717cCxOZfn/PomuAw0YZk1vfYi2jRBI/saVtBrVfUpuOkOtfw0VxxzGARWMEDK/g0a9X7TSkjvzaQhvpv1XiWRM0p8o85EUC8ThNxo3Ln5iw090vD4oR2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jp6--Ds5DfdaBanAHn9tXqPmoiQ== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateDailyNerdMessage < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :daily_nerd_messages, id: :uuid do |t| | ||
t.references :sprint_feedback, null: false, foreign_key: true, type: :uuid | ||
t.string :message, null: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe DailyNerdMessage do | ||
fixtures :all | ||
let(:user) { users(:john) } | ||
let(:daily_nerd_message) { user.sprint_feedbacks.take.daily_nerd_messages.create(message: "I'm a daily nerd") } | ||
|
||
describe "#post_to_slack" do | ||
it "posts the daily nerd message to Slack" do | ||
slack_notification = instance_double("User::SlackNotification") | ||
allow(User::SlackNotification).to receive(:new).with(user).and_return(slack_notification) | ||
expect(slack_notification).to receive(:post_daily_nerd_message).with(daily_nerd_message.message) | ||
|
||
daily_nerd_message.post_to_slack | ||
end | ||
end | ||
end |
Oops, something went wrong.