-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update specs and database_cleaner gem
- Loading branch information
1 parent
2c150ee
commit 5656941
Showing
10 changed files
with
86 additions
and
25 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
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,15 @@ | ||
require 'rails_helper' | ||
|
||
describe MediaMentionsController do | ||
context '#show' do | ||
it 'finds the notice when it exists and renders successfully' do | ||
media_mention = MediaMention.new(title: 'Go Lumen!', scale_of_mention: 'Small') | ||
expect(MediaMention).to receive(:find_by).with(id: '1').and_return(media_mention) | ||
|
||
get :show, params: { id: 1 } | ||
|
||
expect(response).to be_successful | ||
expect(assigns(:media_mention)).to eq media_mention | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,23 +85,6 @@ | |
expect(TokenUrl.count).to eq orig_count | ||
end | ||
|
||
it 'creates a new token and strips out the email part between "+" and "@"' do | ||
allow(controller).to receive(:verify_recaptcha).and_return(true) | ||
|
||
notice = create(:dmca) | ||
|
||
params = { | ||
token_url: { | ||
email: '[email protected]', | ||
notice_id: notice.id | ||
} | ||
} | ||
|
||
post :create, params: params | ||
|
||
expect(TokenUrl.last.email).to eq '[email protected]' | ||
end | ||
|
||
it "won't call the validate method twice" do | ||
allow(controller).to receive(:verify_recaptcha).and_return(true) | ||
allow(controller).to receive(:validate).and_return( | ||
|
@@ -121,6 +104,17 @@ | |
|
||
post :create, params: params | ||
end | ||
|
||
it "won't let to request a new token from the same ip immediately" do | ||
allow(controller).to receive(:verify_recaptcha).and_return(true) | ||
|
||
orig_count = TokenUrl.count | ||
|
||
create_token '[email protected]' | ||
create_token '[email protected]' | ||
|
||
expect(TokenUrl.count).to eq(orig_count + 1) | ||
end | ||
end | ||
|
||
context '#generate_permanent' do | ||
|
@@ -201,6 +195,30 @@ | |
expect(TokenUrl.where(notice: notice, user: user, valid_forever: true).count).to eq(0) | ||
expect_authorization_error | ||
end | ||
|
||
context '#clean_up_email_address' do | ||
it 'downcases a new token email address' do | ||
create_token '[email protected]' | ||
|
||
expect(TokenUrl.last.email).to eq '[email protected]' | ||
end | ||
|
||
it 'removes everything between "+" and "@"' do | ||
create_token '[email protected]' | ||
|
||
expect(TokenUrl.last.email).to eq '[email protected]' | ||
end | ||
|
||
it 'removes periods if a new token email address is gmail' do | ||
create_token '[email protected]' | ||
|
||
expect(TokenUrl.last.email).to eq '[email protected]' | ||
|
||
create_token '[email protected]', '2.2.2.2' | ||
|
||
expect(TokenUrl.last.email).to eq '[email protected]' | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
@@ -209,4 +227,20 @@ def expect_authorization_error | |
expect(session['flash']['flashes']['alert']).to eq 'You are not authorized to access this page.' | ||
expect(response.status).to eq 302 | ||
end | ||
|
||
def create_token(email, ip = '1.1.1.1') | ||
allow_any_instance_of(ActionDispatch::Request).to receive(:remote_ip) { ip } | ||
allow(controller).to receive(:verify_recaptcha).and_return(true) | ||
|
||
notice = create(:dmca) | ||
|
||
params = { | ||
token_url: { | ||
email: email, | ||
notice_id: notice.id | ||
} | ||
} | ||
|
||
post :create, params: params | ||
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,5 @@ | ||
require 'spec_helper' | ||
|
||
describe MediaMention, type: :model do | ||
it { is_expected.to validate_presence_of :scale_of_mention } | ||
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