-
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.
Merge branch 'main' of https://github.com/MichaelSipayung/rails-sampl…
- Loading branch information
Showing
19 changed files
with
381 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# This workflow uses actions that are not certified by GitHub. They are | ||
# provided by a third-party and are governed by separate terms of service, | ||
# privacy policy, and support documentation. | ||
# | ||
# This workflow will install a prebuilt Ruby version, install dependencies, and | ||
# run tests and linters. | ||
name: "Ruby on Rails CI" | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: postgres:11-alpine | ||
ports: | ||
- "5432:5432" | ||
env: | ||
POSTGRES_DB: rails_test | ||
POSTGRES_USER: rails | ||
POSTGRES_PASSWORD: password | ||
env: | ||
RAILS_ENV: test | ||
DATABASE_URL: "postgres://rails:password@localhost:5432/rails_test" | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
# Add or replace dependency steps here | ||
- name: Install Ruby and gems | ||
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 | ||
with: | ||
bundler-cache: true | ||
# Add or replace database setup steps here | ||
- name: Set up database schema | ||
run: bin/rails db:schema:load | ||
# Add or replace test runners here | ||
- name: Run tests | ||
run: bin/rake | ||
|
||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Install Ruby and gems | ||
uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0 | ||
with: | ||
bundler-cache: true | ||
# Add or replace any other lints here | ||
- name: Security audit dependencies | ||
run: bin/bundler-audit --update | ||
- name: Security audit application code | ||
run: bin/brakeman -q -w2 | ||
- name: Lint Ruby files | ||
run: bin/rubocop --parallel |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
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,17 @@ | ||
<!--since we will including stats both user show pages and home page --> | ||
<!-- nothing happen if @user is nil --> | ||
<% @user ||= current_user %> | ||
<div class="stats"> | ||
<a href="<%= following_user_path(@user) %>"> | ||
<strong id="following" class="start"> | ||
<%= @user.following.count %> | ||
</strong> | ||
following | ||
</a> | ||
<a href="<%= followers_user_path(@user) %>"> | ||
<strong id="followers" class="start"> | ||
<%= @user.followers.count %> | ||
</strong> | ||
followers | ||
</a> | ||
</div> |
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,7 @@ | ||
<%= form_with(model: current_user.active_relationships.build, local: true) do |f| %> | ||
<div> | ||
<!-- using hidden field to pass the followed_id to the create action --> | ||
<%= hidden_field_tag :followed_id, @user.id %> | ||
</div> | ||
<%= f.submit "Follow", class: "btn btn-primary"%> | ||
<%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,9 @@ | ||
<% unless current_user==@user%> | ||
<div id="follow_form"> | ||
<% if current_user.following?(@user) %> | ||
<%= render 'unfollow' %> | ||
<% else %> | ||
<%= render 'follow' %> | ||
<% end %> | ||
</div> | ||
<%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,4 @@ | ||
<%=form_with(model: current_user.active_relationships.find_by(followed_id: @user.id), | ||
html: {method: :delete}, local: true) do |f| %> | ||
<%= f.submit "Unfollow", class: "btn"%> | ||
<%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,30 @@ | ||
<% provide(:title, @title) %> | ||
<div class="row"> | ||
<aside class="col-md-4"> | ||
<section class="user_info"> | ||
<%=gravatar_for @user %> | ||
<h1><%= @user.name %></h1> | ||
<span><%= link_to "view my profile", @user %></span> | ||
<span><b>Micropost: </b><%= @user.microposts.count %></span> | ||
</section> | ||
<section class="stats"> | ||
<%= render 'shared/stats' %> | ||
<% if @users.any? %> | ||
<div class="user_avatars"> | ||
<% @users.each do |user| %> | ||
<%= link_to gravatar_for(user), user %> | ||
<%end %> | ||
</div> | ||
<%end %> | ||
</section> | ||
</aside> | ||
<div class="col-md-8"> | ||
<h3><%= @title %></h3> | ||
<%if @users.any? %> | ||
<ul class="users follow"> | ||
<% render @users %> | ||
</ul> | ||
<%= will_paginate %> | ||
<%end %> | ||
</div> | ||
</div> |
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 |
---|---|---|
@@ -1 +1,17 @@ | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
one: | ||
follower: michael | ||
followed: iana | ||
|
||
two: | ||
follower: michael | ||
followed: malory | ||
|
||
three: | ||
follower: iana | ||
followed: michael | ||
|
||
four: | ||
follower: archer | ||
followed: michael | ||
|
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 |
---|---|---|
|
@@ -12,6 +12,18 @@ archer: #for invalid access | |
password_digest: <%=User.digest('password') %> | ||
activated: true | ||
activated_at: <%= Time.zone.now %> | ||
iana: #for invalid access | ||
name: iana sigh | ||
email: [email protected] | ||
password_digest: <%=User.digest('password') %> | ||
activated: true | ||
activated_at: <%= Time.zone.now %> | ||
malory: | ||
name: Malory Archer | ||
email: [email protected] | ||
password_digest: <%=User.digest('password') %> | ||
activated: true | ||
activated_at: <%= Time.zone.now %> | ||
one: | ||
name: MyString | ||
email: user_one_<%= Time.now.to_f %>@example.com | ||
|
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,25 @@ | ||
require "test_helper" | ||
|
||
class FollowingTest < ActionDispatch::IntegrationTest | ||
def setup | ||
@user = users(:michael) | ||
get login_path | ||
post login_path, params: {session: {email: @user.email, password: 'password'}} | ||
end | ||
test "following page" do | ||
get following_user_path(@user) | ||
assert_not @user.following.empty? | ||
assert_match @user.following.count.to_s, response.body | ||
@user.following.each do |user| | ||
assert_select 'a[href=?]', user_path(user) #check if the link is correct | ||
end | ||
end | ||
test "followers page" do | ||
get followers_user_path(@user) | ||
assert_not @user.followers.empty? | ||
assert_match @user.followers.count.to_s, response.body #check if the link is correct | ||
@user.followers.each do |user| | ||
assert_select 'a[href=?]', user_path(user) | ||
end | ||
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