Skip to content

Commit

Permalink
add sign out functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
jasylwong committed Feb 27, 2020
1 parent 12cdb5c commit 6acf6fd
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 7 deletions.
8 changes: 7 additions & 1 deletion app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class MakersBnB < Sinatra::Base
session[:user_id] = User.find_by(email: params['email']).id
redirect('/spaces')
else
flash[:notice] = 'Wrong credentials, dummy! :( '
flash[:notice1] = 'Wrong credentials, dummy! :( '
redirect('/sessions/new')
end
end
Expand All @@ -62,6 +62,12 @@ class MakersBnB < Sinatra::Base
get '/welcome' do
"Welcome, #{User.all.last.name}"
end

post '/sessions/destroy' do
session.clear
flash[:notice2] = "You have successfully signed out"
redirect('/sessions/new')
end

run! if app_file == $0
end
Expand Down
19 changes: 18 additions & 1 deletion coverage/.resultset.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@
null
]
},
"/Users/student/Programming/Makers/Projects/MakersBnB/spec/features/logging_out_spec.rb": {
"lines": [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
null,
null,
null
]
},
"/Users/student/Programming/Makers/Projects/MakersBnB/spec/features/logging_page_spec.rb": {
"lines": [
1,
Expand Down Expand Up @@ -165,6 +182,6 @@
]
}
},
"timestamp": 1582762378
"timestamp": 1582796737
}
}
193 changes: 189 additions & 4 deletions coverage/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<img src="./assets/0.12.1/loading.gif" alt="loading"/>
</div>
<div id="wrapper" class="hide">
<div class="timestamp">Generated <abbr class="timeago" title="2020-02-27T00:12:58+00:00">2020-02-27T00:12:58+00:00</abbr></div>
<div class="timestamp">Generated <abbr class="timeago" title="2020-02-27T09:45:37+00:00">2020-02-27T09:45:37+00:00</abbr></div>
<ul class="group_tabs"></ul>

<div id="content">
Expand All @@ -39,12 +39,12 @@ <h2>
<a name="AllFiles"></a>

<div>
<b>7</b> files in total.
<b>8</b> files in total.
</div>

<div class="t-line-summary">
<b>76</b> relevant lines,
<span class="green"><b>76</b> lines covered</span> and
<b>86</b> relevant lines,
<span class="green"><b>86</b> lines covered</span> and
<span class="red"><b>0</b> lines missed. </span>
(<span class="green">
100.0%
Expand Down Expand Up @@ -81,6 +81,17 @@ <h2>

</tr>

<tr class="t-file">
<td class="strong t-file__name"><a href="#e569cdd3468d9e2d60ee3a83c825219a110924ae" class="src_link" title="spec/features/logging_out_spec.rb">spec/features/logging_out_spec.rb</a></td>
<td class="green strong cell--number t-file__coverage">100.00 %</td>
<td class="cell--number">13</td>
<td class="cell--number">10</td>
<td class="cell--number">10</td>
<td class="cell--number">0</td>
<td class="cell--number">1.00</td>

</tr>

<tr class="t-file">
<td class="strong t-file__name"><a href="#a9ebcad501d01cffed9f2e5ca01d128572368ba4" class="src_link" title="spec/features/logging_page_spec.rb">spec/features/logging_page_spec.rb</a></td>
<td class="green strong cell--number t-file__coverage">100.00 %</td>
Expand Down Expand Up @@ -316,6 +327,180 @@ <h4>
</div>


<div class="source_table" id="e569cdd3468d9e2d60ee3a83c825219a110924ae">
<div class="header">
<h3>spec/features/logging_out_spec.rb</h3>
<h4>
<span class="green">
100.0%
</span>

lines covered
</h4>



<div class="t-line-summary">
<b>10</b> relevant lines.
<span class="green"><b>10</b> lines covered</span> and
<span class="red"><b>0</b> lines missed.</span>
</div>



</div>

<pre>
<ol>

<div>
<li class="covered" data-hits="1" data-linenumber="1">
<span class="hits">1</span>




<code class="ruby">feature &#39;logging out&#39; do</code>
</li>
</div>

<div>
<li class="covered" data-hits="1" data-linenumber="2">
<span class="hits">1</span>




<code class="ruby"> scenario &#39;a user can log out&#39; do</code>
</li>
</div>

<div>
<li class="covered" data-hits="1" data-linenumber="3">
<span class="hits">1</span>




<code class="ruby"> User.create(name: &#39;Jiminy cricket&#39;, email: &#39;[email protected]&#39;, password: &#39;pinocchio&#39;)</code>
</li>
</div>

<div>
<li class="covered" data-hits="1" data-linenumber="4">
<span class="hits">1</span>




<code class="ruby"> visit(&#39;/sessions/new&#39;)</code>
</li>
</div>

<div>
<li class="covered" data-hits="1" data-linenumber="5">
<span class="hits">1</span>




<code class="ruby"> expect(current_path).to eq(&#39;/sessions/new&#39;)</code>
</li>
</div>

<div>
<li class="covered" data-hits="1" data-linenumber="6">
<span class="hits">1</span>




<code class="ruby"> fill_in(&#39;email&#39;, with: &#39;[email protected]&#39;)</code>
</li>
</div>

<div>
<li class="covered" data-hits="1" data-linenumber="7">
<span class="hits">1</span>




<code class="ruby"> fill_in(&#39;password&#39;, with: &#39;pinocchio&#39;)</code>
</li>
</div>

<div>
<li class="covered" data-hits="1" data-linenumber="8">
<span class="hits">1</span>




<code class="ruby"> click_button(&#39;Submit&#39;)</code>
</li>
</div>

<div>
<li class="covered" data-hits="1" data-linenumber="9">
<span class="hits">1</span>




<code class="ruby"> click_button(&#39;Sign out&#39;)</code>
</li>
</div>

<div>
<li class="covered" data-hits="1" data-linenumber="10">
<span class="hits">1</span>




<code class="ruby"> expect(page).to have_content(&#39;You have successfully signed out&#39;) </code>
</li>
</div>

<div>
<li class="never" data-hits="" data-linenumber="11">





<code class="ruby"> end</code>
</li>
</div>

<div>
<li class="never" data-hits="" data-linenumber="12">





<code class="ruby">end</code>
</li>
</div>

<div>
<li class="never" data-hits="" data-linenumber="13">





<code class="ruby"></code>
</li>
</div>

</ol>
</pre>
</div>


<div class="source_table" id="a9ebcad501d01cffed9f2e5ca01d128572368ba4">
<div class="header">
<h3>spec/features/logging_page_spec.rb</h3>
Expand Down
13 changes: 13 additions & 0 deletions spec/features/logging_out_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
feature 'logging out' do
scenario 'a user can log out' do
User.create(name: 'Jiminy cricket', email: '[email protected]', password: 'pinocchio')
visit('/sessions/new')
expect(current_path).to eq('/sessions/new')
fill_in('email', with: '[email protected]')
fill_in('password', with: 'pinocchio')
click_button('Submit')
click_button('Sign out')
expect(page).to have_content('You have successfully signed out')
end
end

3 changes: 2 additions & 1 deletion views/sessions/new.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ f {

<h1>Login in below, friends!</h1>

<h2><%= flash[:notice] %></h2>
<h2><%= flash[:notice1] %></h2>
<h2><%= flash[:notice2] %></h2>

<form action="/sessions" method="post">

Expand Down
4 changes: 4 additions & 0 deletions views/spaces/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<h1>MakersBnB</h1>

<h2>Welcome <%= User.find_by(id: session[:user_id]).name %></h2>
<a href='/spaces/new'><button>Create new space</button></a>
<form action="/sessions/destroy" method="post">
<input type="submit" value='Sign out' />
</form>

<% Space.all.each do |space| %>
<img src='<%= space.photo_url %>' height='420' width='auto'></br>
Expand Down

0 comments on commit 6acf6fd

Please sign in to comment.