Skip to content

Commit

Permalink
Merge branch 'master' into master-legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
thatandromeda committed Sep 12, 2018
2 parents e4155f1 + 35d6a46 commit 26e636d
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 148 deletions.
10 changes: 5 additions & 5 deletions app/models/government_request.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class GovernmentRequest < Notice

DEFAULT_ENTITY_NOTICE_ROLES = %w|recipient sender principal|
DEFAULT_ENTITY_NOTICE_ROLES = %w[recipient sender principal submitter].freeze
acts_as_taggable_on :regulations

define_elasticsearch_mapping
Expand All @@ -11,11 +10,12 @@ class GovernmentRequest < Notice
'Email',
'Records Preservation',
'Subpoena',
'Warrant',
]
'Warrant'
].freeze

validates_inclusion_of :request_type,
in: VALID_REQUEST_TYPES, allow_blank: true
in: VALID_REQUEST_TYPES,
allow_blank: true

def self.model_name
Notice.model_name
Expand Down
8 changes: 7 additions & 1 deletion lib/tasks/chillingeffects.rake → lib/tasks/lumen.rake
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,12 @@ where works.id in (
# atomic file write process linked above.
desc 'safer cache clear'
task safer_cache_clear: :environment do
system("cd #{__dir__}/../../tmp/cache && find . -amin +20 -delete")
# Go to cache dir;
# clear out any files more than 20 minutes old;
# remove empty directories.
cmd = "cd #{__dir__}/../../tmp/cache && " \
'find . -type f -amin +20 -delete && ' \
'find . -type d -empty -delete'
system(cmd)
end
end
127 changes: 64 additions & 63 deletions spec/controllers/notices_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'rails_helper'

describe NoticesController do
context "#show" do
it "finds the notice by ID" do
context '#show' do
it 'finds the notice by ID' do
notice = Notice.new
expect(Notice).to receive(:find).with('42').and_return(notice)

Expand All @@ -11,8 +11,8 @@
expect(assigns(:notice)).to eq notice
end

context "as HTML" do
it "renders the show template" do
context 'as HTML' do
it 'renders the show template' do
stub_find_notice

get :show, id: 1
Expand All @@ -21,7 +21,7 @@
expect(response).to render_template(:show)
end

it "renders the rescinded template if the notice is rescinded" do
it 'renders the rescinded template if the notice is rescinded' do
stub_find_notice(build(:dmca, rescinded: true))

get :show, id: 1
Expand All @@ -31,14 +31,15 @@
end
end

context "as JSON" do
context 'as JSON' do
Notice.type_models.each do |model_class|
it "returns a serialized notice for #{model_class}" do
notice = stub_find_notice(model_class.new)
serializer_class = model_class.active_model_serializer || NoticeSerializer
serialized = serializer_class.new(notice)
expect(serializer_class).to receive(:new).
with(notice, anything).and_return(serialized)
expect(serializer_class).to receive(:new)
.with(notice, anything)
.and_return(serialized)

get :show, id: 1, format: :json

Expand All @@ -55,54 +56,54 @@

get :show, id: 1, format: :json

json = JSON.parse(response.body)["dmca"]
json = JSON.parse(response.body)['dmca']
expect(json).to have_key('id').with_value(notice.id)
expect(json).to have_key('title').with_value(notice.title)
expect(json).to have_key('body').with_value("Notice Rescinded")
expect(json).to have_key('body').with_value('Notice Rescinded')
end

it "returns original URLs for a Notice if you are a researcher" do
it 'returns original URLs for a Notice if you are a researcher' do
user = create(:user, roles: [Role.researcher])
params = {
notice: {
title: "A title",
type: "DMCA",
subject: "Infringement Notfication via Blogger Complaint",
date_sent: "2013-05-22",
date_received: "2013-05-23",
title: 'A title',
type: 'DMCA',
subject: 'Infringement Notfication via Blogger Complaint',
date_sent: '2013-05-22',
date_received: '2013-05-23',
works_attributes: [
{
description: "The Avengers",
description: 'The Avengers',
infringing_urls_attributes: [
{ url: "http://youtube.com/bad_url_1" },
{ url: "http://youtube.com/bad_url_2" },
{ url: "http://youtube.com/bad_url_3" }
{ url: 'http://youtube.com/bad_url_1' },
{ url: 'http://youtube.com/bad_url_2' },
{ url: 'http://youtube.com/bad_url_3' }
]
}
],
entity_notice_roles_attributes: [
{
name: "recipient",
name: 'recipient',
entity_attributes: {
name: "Google",
kind: "organization",
address_line_1: "1600 Amphitheatre Parkway",
city: "Mountain View",
state: "CA",
zip: "94043",
country_code: "US"
name: 'Google',
kind: 'organization',
address_line_1: '1600 Amphitheatre Parkway',
city: 'Mountain View',
state: 'CA',
zip: '94043',
country_code: 'US'
}
},
{
name: "sender",
name: 'sender',
entity_attributes: {
name: "Joe Lawyer",
kind: "individual",
address_line_1: "1234 Anystreet St.",
city: "Anytown",
state: "CA",
zip: "94044",
country_code: "US"
name: 'Joe Lawyer',
kind: 'individual',
address_line_1: '1234 Anystreet St.',
city: 'Anytown',
state: 'CA',
zip: '94044',
country_code: 'US'
}
}
]
Expand All @@ -116,7 +117,7 @@
request.env['HTTP_AUTHENTICATION_TOKEN'] = user.authentication_token
get :show, id: 1, format: :json

json = JSON.parse(response.body)["dmca"]["works"][0]["infringing_urls"][0]
json = JSON.parse(response.body)['dmca']['works'][0]['infringing_urls'][0]
expect(json).to have_key('url_original')
end
end
Expand All @@ -127,53 +128,53 @@ def stub_find_notice(notice = nil)
end
end

context "#create" do
context "format-independent logic" do
context '#create' do
context 'format-independent logic' do
before do
@submit_notice = double("SubmitNotice").as_null_object
@notice_params = HashWithIndifferentAccess.new(title: "A title")
@submit_notice = double('SubmitNotice').as_null_object
@notice_params = HashWithIndifferentAccess.new(title: 'A title')
end

it "initializes a DMCA by default from params" do
expect(SubmitNotice).to receive(:new).
with(DMCA, @notice_params).
and_return(@submit_notice)
it 'initializes a DMCA by default from params' do
expect(SubmitNotice).to receive(:new)
.with(DMCA, @notice_params)
.and_return(@submit_notice)

post :create, notice: @notice_params
end

it "uses the type param to instantiate the correct class" do
expect(SubmitNotice).to receive(:new).
with(Trademark, @notice_params).
and_return(@submit_notice)
it 'uses the type param to instantiate the correct class' do
expect(SubmitNotice).to receive(:new)
.with(Trademark, @notice_params)
.and_return(@submit_notice)

post :create, notice: @notice_params.merge(type: 'trademark')
end

it "defaults to DMCA if the type is missing or invalid" do
it 'defaults to DMCA if the type is missing or invalid' do
invalid_types = ['', 'FlimFlam', 'Object', 'User', 'Hash']

expect(SubmitNotice).to receive(:new).
exactly(5).times.
with(DMCA, @notice_params).
and_return(@submit_notice)
expect(SubmitNotice).to receive(:new)
.exactly(5).times
.with(DMCA, @notice_params)
.and_return(@submit_notice)

invalid_types.each do |invalid_type|
post :create, notice: @notice_params.merge(type: invalid_type)
end
end
end

context "as HTML" do
it "redirects when saved successfully" do
context 'as HTML' do
it 'redirects when saved successfully' do
stub_submit_notice

post_create

expect(response).to redirect_to(:root)
end

it "renders the new template when unsuccessful" do
it 'renders the new template when unsuccessful' do
submit_notice = stub_submit_notice
allow(submit_notice).to receive(:submit).and_return(false)

Expand All @@ -184,15 +185,15 @@ def stub_find_notice(notice = nil)
end
end

context "as JSON" do
context 'as JSON' do
before do
@ability = Object.new
@ability.extend(CanCan::Ability)
@ability.can(:submit, Notice)
allow(controller).to receive(:current_ability) { @ability }
end

it "returns unauthorized if one cannot submit" do
it 'returns unauthorized if one cannot submit' do
stub_submit_notice
@ability.cannot(:submit, Notice)

Expand All @@ -201,7 +202,7 @@ def stub_find_notice(notice = nil)
expect(response.status).to eq 401
end

it "returns a proper Location header when saved successfully" do
it 'returns a proper Location header when saved successfully' do
notice = build_stubbed(:dmca)
submit_notice = stub_submit_notice
allow(submit_notice).to receive(:notice).and_return(notice)
Expand All @@ -212,7 +213,7 @@ def stub_find_notice(notice = nil)
expect(response.headers['Location']).to eq notice_url(notice)
end

it "returns a useful status code when there are errors" do
it 'returns a useful status code when there are errors' do
submit_notice = stub_submit_notice
allow(submit_notice).to receive(:submit).and_return(false)

Expand All @@ -221,7 +222,7 @@ def stub_find_notice(notice = nil)
expect(response).to be_unprocessable
end

it "includes any errors in the response" do
it 'includes any errors in the response' do
submit_notice = stub_submit_notice
allow(submit_notice).to receive(:submit).and_return(false)
allow(submit_notice).to receive(:errors).and_return(
Expand All @@ -245,7 +246,7 @@ def stub_submit_notice
end

def post_create(format = :html)
post :create, notice: { title: "A title" }, format: format
post :create, notice: { title: 'A title' }, format: format
end

def mock_errors(model, field_errors = {})
Expand Down
Loading

0 comments on commit 26e636d

Please sign in to comment.