File tree Expand file tree Collapse file tree 5 files changed +18
-10
lines changed Expand file tree Collapse file tree 5 files changed +18
-10
lines changed Original file line number Diff line number Diff line change 1
1
class PagesController < ApplicationController
2
2
def index
3
3
@comments = Comment . all
4
- @git_commit_sha = GitCommitSha . current_sha
5
4
6
5
# NOTE: The below notes apply if you want to set the value of the props in the controller, as
7
6
# compared to he view. However, it's more convenient to use Jbuilder from the view. See
Original file line number Diff line number Diff line change 1
1
module PagesHelper
2
+ def git_commit_sha
3
+ GitCommitSha . current_sha
4
+ end
5
+
6
+ def git_commit_sha_short
7
+ full_sha = git_commit_sha
8
+ full_sha . slice ( full_sha . size - 7 , full_sha . size )
9
+ end
2
10
end
Original file line number Diff line number Diff line change 1
1
class GitCommitSha
2
2
def self . current_sha
3
- return @commit_sha unless @commit_sha . blank?
4
- @commit_sha = ( retrieve_sha_from_env_var || retrieve_sha_from_git_folder )
3
+ @commit_sha ||= retrieve_sha_from_env_var . presence || retrieve_sha_from_git_folder
5
4
end
6
5
7
6
def self . current_sha = ( sha )
8
7
@commit_sha = sha
9
8
end
10
9
11
10
def self . reset_current_sha
12
- self . current_sha = ""
11
+ self . current_sha = nil
13
12
end
14
13
15
14
def self . retrieve_sha_from_git_folder
@@ -18,6 +17,6 @@ def self.retrieve_sha_from_git_folder
18
17
19
18
def self . retrieve_sha_from_env_var
20
19
env_var = ENV [ "DEPLOYMENT_SHA" ]
21
- env_var . blank? ? false : env_var
20
+ env_var . blank? ? nil : env_var
22
21
end
23
22
end
Original file line number Diff line number Diff line change 1
1
< h2 > Using React + Redux + Rails Backend (using the react_on_rails gem)</ h2 >
2
- < p > current Git commit :
3
- < span id =" current-git-commit-sha " >
4
- <%= @git_commit_sha %>
5
- </ span >
2
+ < p > Current Commit :
3
+ <%= link_to git_commit_sha_short ,
4
+ "https://github.com/shakacode/react-webpack-rails-tutorial/commit/ #{ git_commit_sha } " ,
5
+ id : "git-commit-sha" % >
6
6
</ p >
7
7
< ul >
8
8
< li >
Original file line number Diff line number Diff line change 6
6
after { ENV [ "DEPLOYMENT_SHA" ] = old_sha }
7
7
background { visit root_path }
8
8
it "displays the current git commit" do
9
- expect ( page ) . to have_css ( "#current- git-commit-sha" , text : sha )
9
+ expect ( page ) . to have_css ( "#git-commit-sha" , text : expected_text )
10
10
end
11
11
end
12
12
13
13
feature "Git Commit SHA" do
14
14
context "when env var is not set" do
15
15
let ( :sha ) { "94d92356828a56db25fccff9d50f41c525eead5x" }
16
+ let ( :expected_text ) { "5eead5x" }
16
17
before { GitCommitSha . current_sha = sha }
17
18
it_behaves_like "Git Commit SHA"
18
19
end
19
20
context "when env var is set" do
20
21
let ( :sha ) { "94d92356828a56db25fccff9d50f41c525eead5y" }
22
+ let ( :expected_text ) { "5eead5y" }
21
23
before do
22
24
ENV [ "DEPLOYMENT_SHA" ] = sha
23
25
GitCommitSha . reset_current_sha
You can’t perform that action at this time.
0 commit comments