Use webmock instead of fakeweb for VCR; Fix tests; Use Timecop to speed up tests previously using sleep; Move artist rename into seperate operation

This commit is contained in:
r888888888
2013-05-24 12:59:13 -07:00
parent 9dfb8aa33e
commit 4dff618863
17 changed files with 4877 additions and 4760 deletions

View File

@@ -8,7 +8,8 @@ group :test do
gem "simplecov", :require => false gem "simplecov", :require => false
gem "pry" gem "pry"
gem "vcr" gem "vcr"
gem "fakeweb" gem "webmock"
gem "timecop"
end end
group :assets do group :assets do

View File

@@ -53,6 +53,7 @@ GEM
activesupport (3.2.12) activesupport (3.2.12)
i18n (~> 0.6) i18n (~> 0.6)
multi_json (~> 1.0) multi_json (~> 1.0)
addressable (2.3.4)
arel (3.0.2) arel (3.0.2)
awesome_print (1.1.0) awesome_print (1.1.0)
aws-s3 (0.6.3) aws-s3 (0.6.3)
@@ -73,6 +74,7 @@ GEM
capistrano capistrano
chronic (0.9.1) chronic (0.9.1)
coderay (1.0.9) coderay (1.0.9)
crack (0.3.2)
daemons (1.1.9) daemons (1.1.9)
delayed_job (3.0.5) delayed_job (3.0.5)
activesupport (~> 3.0) activesupport (~> 3.0)
@@ -87,7 +89,6 @@ GEM
multi_json (~> 1.0) multi_json (~> 1.0)
factory_girl (4.2.0) factory_girl (4.2.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
fakeweb (1.3.0)
highline (1.6.18) highline (1.6.18)
hike (1.2.1) hike (1.2.1)
i18n (0.6.4) i18n (0.6.4)
@@ -184,6 +185,7 @@ GEM
ref ref
thor (0.18.1) thor (0.18.1)
tilt (1.3.6) tilt (1.3.6)
timecop (0.6.1)
treetop (1.4.12) treetop (1.4.12)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
@@ -199,6 +201,9 @@ GEM
rack rack
raindrops (~> 0.7) raindrops (~> 0.7)
vcr (2.4.0) vcr (2.4.0)
webmock (1.11.0)
addressable (>= 2.2.7)
crack (>= 0.3.2)
webrobots (0.1.1) webrobots (0.1.1)
whenever (0.8.2) whenever (0.8.2)
activesupport (>= 2.3.4) activesupport (>= 2.3.4)
@@ -218,7 +223,6 @@ DEPENDENCIES
delayed_job_active_record delayed_job_active_record
diff-lcs diff-lcs
factory_girl factory_girl
fakeweb
ffaker! ffaker!
mechanize! mechanize!
memcache-client memcache-client
@@ -239,7 +243,9 @@ DEPENDENCIES
simplecov simplecov
term-ansicolor term-ansicolor
therubyracer therubyracer
timecop
uglifier (>= 1.0.3) uglifier (>= 1.0.3)
unicorn unicorn
vcr vcr
webmock
whenever whenever

View File

@@ -13,6 +13,17 @@ class ArtistsController < ApplicationController
respond_with(@artist) respond_with(@artist)
end end
def edit_name
@artist = Artist.find(params[:id])
respond_with(@artist)
end
def update_name
@artist = Artist.find(params[:id])
@artist.update_attribute(:name, params[:artist][:name])
respond_with(@artist)
end
def banned def banned
@artists = Artist.where("is_banned = ?", true).order("name") @artists = Artist.where("is_banned = ?", true).order("name")
respond_with(@artists) do |format| respond_with(@artists) do |format|

View File

@@ -148,18 +148,11 @@ class Artist < ActiveRecord::Base
end end
def notes=(msg) def notes=(msg)
if name_changed? && name_was.present?
wiki_page = WikiPage.titled(name_was).first
end
if wiki_page if wiki_page
wiki_page.title = name
wiki_page.body = msg wiki_page.body = msg
wiki_page.save if wiki_page.body_changed? || wiki_page.title_changed? wiki_page.save if wiki_page.body_changed? || wiki_page.title_changed?
else elsif msg.present?
if msg.present? self.wiki_page = WikiPage.new(:title => name, :body => msg)
self.wiki_page = WikiPage.new(:title => name, :body => msg)
end
end end
end end
end end

View File

@@ -241,6 +241,10 @@ class User < ActiveRecord::Base
end end
end end
def promote_to(level)
update_attributes({:level => level}, :as => :admin)
end
def promote_to_admin_if_first_user def promote_to_admin_if_first_user
return if Rails.env.test? return if Rails.env.test?

View File

@@ -1,9 +1,13 @@
<%= simple_form_for(@artist) do |f| %> <%= simple_form_for(@artist) do |f| %>
<div class="input"> <div class="input">
<label for="artist_name">Name</label> <label for="artist_name">Name</label>
<%= text_field "artist", "name" %> <% if @artist.new_record? %>
[<%= link_to "check", "#", :id => "check-name-link" %>] <%= text_field "artist", "name" %>
<span id="check-name-result"></span> [<%= link_to "check", "#", :id => "check-name-link" %>]
<span id="check-name-result"></span>
<% else %>
<p><%= @artist.name %></p>
<% end %>
</div> </div>
<%= f.input :other_names_comma, :hint => "Separate with commas", :as => :text, :label => "Other names" %> <%= f.input :other_names_comma, :hint => "Separate with commas", :as => :text, :label => "Other names" %>
<%= f.input :group_name %> <%= f.input :group_name %>

View File

@@ -11,6 +11,7 @@
<li><%= link_to "Show", artist_path(@artist) %></li> <li><%= link_to "Show", artist_path(@artist) %></li>
<% if CurrentUser.is_member? %> <% if CurrentUser.is_member? %>
<li><%= link_to "Edit", edit_artist_path(@artist) %></li> <li><%= link_to "Edit", edit_artist_path(@artist) %></li>
<li><%= link_to "Edit name", edit_name_artist_path(@artist) %></li>
<% end %> <% end %>
<li><%= link_to "History", artist_versions_path(:search => {:artist_id => @artist.id}) %></li> <li><%= link_to "History", artist_versions_path(:search => {:artist_id => @artist.id}) %></li>
<% if CurrentUser.is_admin? %> <% if CurrentUser.is_admin? %>

View File

@@ -0,0 +1,19 @@
<div id="c-artists">
<div id="a-edit">
<%= render "sidebar" %>
<section id="content">
<h1>Edit Artist Name</h1>
<%= form_tag(update_name_artist_path(@artist), :method => :put) do %>
<div class="input"><label for="artist_name">Name</label> <%= text_field :artist, :name %></div>
<div><%= submit_tag "Submit" %></div>
<% end %>
</section>
</div>
</div>
<%= render "secondary_links" %>
<% content_for(:page_title) do %>
Edit Artist Name - <%= Danbooru.config.app_name %>
<% end %>

View File

@@ -59,6 +59,8 @@ Danbooru::Application.routes.draw do
member do member do
put :revert put :revert
put :ban put :ban
get :edit_name
put :update_name
end end
collection do collection do
get :show_or_new get :show_or_new

File diff suppressed because it is too large Load Diff

View File

@@ -7,44 +7,44 @@ http_interactions:
encoding: US-ASCII encoding: US-ASCII
string: '' string: ''
headers: headers:
referer: Referer:
- http://www.pixiv.net - http://www.pixiv.net
user-agent: User-Agent:
- ./2.8.0 - ./2.12.0
accept: Accept:
- ! '*/*' - ! '*/*'
response: response:
status: status:
code: 200 code: 200
message: OK message: OK
headers: headers:
server: Server:
- nginx - nginx
date: Date:
- Fri, 03 May 2013 23:23:12 GMT - Fri, 24 May 2013 19:51:22 GMT
content-type: Content-Type:
- image/png - image/png
content-length: Content-Length:
- '1782713' - '1782713'
connection: Connection:
- keep-alive - keep-alive
last-modified: Last-Modified:
- Wed, 14 Sep 2011 17:28:13 GMT - Wed, 14 Sep 2011 17:28:13 GMT
etag: Etag:
- ! '"2e3303bf-1b33b9-4acea15afa540"' - ! '"2e3303bf-1b33b9-4acea15afa540"'
accept-ranges: Accept-Ranges:
- bytes - bytes
cache-control: Cache-Control:
- max-age=1209600 - max-age=1209600
expires: Expires:
- Fri, 17 May 2013 23:23:12 GMT - Fri, 07 Jun 2013 00:30:29 GMT
age: Age:
- '0' - '69653'
body: body:
encoding: US-ASCII encoding: US-ASCII
string: '' string: ''
http_version: '1.1' http_version:
recorded_at: Fri, 03 May 2013 23:23:12 GMT recorded_at: Fri, 24 May 2013 19:51:22 GMT
- request: - request:
method: get method: get
uri: http://img65.pixiv.net/img/kiyoringo/21755794_big_p2.png uri: http://img65.pixiv.net/img/kiyoringo/21755794_big_p2.png
@@ -52,39 +52,39 @@ http_interactions:
encoding: US-ASCII encoding: US-ASCII
string: '' string: ''
headers: headers:
user-agent: User-Agent:
- _/2.8.0 - _/2.12.0
referer: Referer:
- http://www.pixiv.net - http://www.pixiv.net
accept: Accept:
- ! '*/*' - ! '*/*'
response: response:
status: status:
code: 200 code: 200
message: OK message: OK
headers: headers:
server: Server:
- nginx - nginx
date: Date:
- Fri, 03 May 2013 23:23:12 GMT - Fri, 24 May 2013 19:51:22 GMT
content-type: Content-Type:
- image/png - image/png
content-length: Content-Length:
- '1782713' - '1782713'
connection: Connection:
- keep-alive - keep-alive
last-modified: Last-Modified:
- Wed, 14 Sep 2011 17:28:13 GMT - Wed, 14 Sep 2011 17:28:13 GMT
etag: Etag:
- ! '"2e3303bf-1b33b9-4acea15afa540"' - ! '"2e3303bf-1b33b9-4acea15afa540"'
accept-ranges: Accept-Ranges:
- bytes - bytes
cache-control: Cache-Control:
- max-age=1209600 - max-age=1209600
expires: Expires:
- Fri, 17 May 2013 23:23:12 GMT - Fri, 07 Jun 2013 00:30:29 GMT
age: Age:
- '0' - '69653'
body: body:
encoding: ASCII-8BIT encoding: ASCII-8BIT
string: !binary |- string: !binary |-
@@ -39704,6 +39704,6 @@ http_interactions:
AgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAAB AgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAAB
AgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAAB AgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAABAgQIECBAgAAB
AgQIECBAgAABAgQIECDwAYE/YMgpRKYZ7IsAAAAASUVORK5CYII= AgQIECBAgAABAgQIECDwAYE/YMgpRKYZ7IsAAAAASUVORK5CYII=
http_version: '1.1' http_version:
recorded_at: Fri, 03 May 2013 23:23:17 GMT recorded_at: Fri, 24 May 2013 19:51:25 GMT
recorded_with: VCR 2.4.0 recorded_with: VCR 2.4.0

View File

@@ -7,51 +7,39 @@ http_interactions:
encoding: US-ASCII encoding: US-ASCII
string: '' string: ''
headers: headers:
user-agent: User-Agent:
- _/2.8.0 - _/2.12.0
referer: Referer:
- http://www.pixiv.net - http://www.pixiv.net
accept: Accept:
- ! '*/*' - ! '*/*'
response: response:
status: status:
code: 200 code: 200
message: !binary |- message: OK
T0s=
headers: headers:
!binary "c2VydmVy": Server:
- !binary |- - nginx
bmdpbng= Date:
!binary "ZGF0ZQ==": - Fri, 24 May 2013 19:51:25 GMT
- !binary |- Content-Type:
RnJpLCAwMyBNYXkgMjAxMyAyMzoyMzoxOCBHTVQ= - image/jpeg
!binary "Y29udGVudC10eXBl": Content-Length:
- !binary |- - '185778'
aW1hZ2UvanBlZw== Connection:
!binary "Y29udGVudC1sZW5ndGg=": - keep-alive
- !binary |- Last-Modified:
MTg1Nzc4 - Tue, 19 May 2009 23:34:11 GMT
!binary "Y29ubmVjdGlvbg==": Etag:
- !binary |- - ! '"add11c9-2d5b2-46a4c590e22c0"'
a2VlcC1hbGl2ZQ== Accept-Ranges:
!binary "bGFzdC1tb2RpZmllZA==": - bytes
- !binary |- Cache-Control:
VHVlLCAxOSBNYXkgMjAwOSAyMzozNDoxMSBHTVQ= - max-age=1209600
!binary "ZXRhZw==": Expires:
- !binary |- - Thu, 06 Jun 2013 22:56:47 GMT
ImFkZDExYzktMmQ1YjItNDZhNGM1OTBlMjJjMCI= Age:
!binary "YWNjZXB0LXJhbmdlcw==": - '75278'
- !binary |-
Ynl0ZXM=
!binary "Y2FjaGUtY29udHJvbA==":
- !binary |-
bWF4LWFnZT0xMjA5NjAw
!binary "ZXhwaXJlcw==":
- !binary |-
RnJpLCAxNyBNYXkgMjAxMyAxMTozMTozMyBHTVQ=
!binary "YWdl":
- !binary |-
NDI3MDU=
body: body:
encoding: ASCII-8BIT encoding: ASCII-8BIT
string: !binary |- string: !binary |-
@@ -4184,7 +4172,6 @@ http_interactions:
DvGOzZcGUrHy3Ep4MunzY5Ue4KSoe+oGXGtuq4FVkqjqSa+gLfx3N0nxMF54 DvGOzZcGUrHy3Ep4MunzY5Ue4KSoe+oGXGtuq4FVkqjqSa+gLfx3N0nxMF54
uS9vPLxbgUolXkf60QkHs5F291RMWfqRh/kmOpY7fIklQbpB7wD9danFlWB5 uS9vPLxbgUolXkf60QkHs5F291RMWfqRh/kmOpY7fIklQbpB7wD9danFlWB5
bJUdD6Cp8Tgup+OwhWnRD//Z bJUdD6Cp8Tgup+OwhWnRD//Z
http_version: !binary |- http_version:
MS4x recorded_at: Fri, 24 May 2013 19:51:26 GMT
recorded_at: Fri, 03 May 2013 23:23:18 GMT
recorded_with: VCR 2.4.0 recorded_with: VCR 2.4.0

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -92,6 +92,6 @@ MEMCACHE = MockMemcache.new
VCR.configure do |c| VCR.configure do |c|
c.cassette_library_dir = "test/fixtures/vcr_cassettes" c.cassette_library_dir = "test/fixtures/vcr_cassettes"
c.hook_into :fakeweb c.hook_into :webmock
c.allow_http_connections_when_no_cassette = true c.allow_http_connections_when_no_cassette = true
end end

View File

@@ -67,8 +67,9 @@ class CommentTest < ActiveSupport::TestCase
Danbooru.config.stubs(:comment_threshold).returns(1) Danbooru.config.stubs(:comment_threshold).returns(1)
p = FactoryGirl.create(:post) p = FactoryGirl.create(:post)
c1 = FactoryGirl.create(:comment, :post => p) c1 = FactoryGirl.create(:comment, :post => p)
sleep 1 Timecop.travel(2.seconds.from_now) do
c2 = FactoryGirl.create(:comment, :post => p) c2 = FactoryGirl.create(:comment, :post => p)
end
p.reload p.reload
assert_equal(c1.created_at.to_s, p.last_commented_at.to_s) assert_equal(c1.created_at.to_s, p.last_commented_at.to_s)
end end

View File

@@ -21,8 +21,9 @@ class ForumPostTest < ActiveSupport::TestCase
9.times do 9.times do
@posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000)) @posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
end end
sleep 2 Timecop.travel(2.seconds.from_now) do
@posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000)) @posts << FactoryGirl.create(:forum_post, :topic_id => @topic.id, :body => rand(100_000))
end
end end
should "know which page it's on" do should "know which page it's on" do
@@ -59,11 +60,12 @@ class ForumPostTest < ActiveSupport::TestCase
end end
should "update its parent when saved" do should "update its parent when saved" do
sleep 1 Timecop.travel(1.second.from_now) do
original_topic_updated_at = @topic.updated_at @original_topic_updated_at = @topic.updated_at
end
post = FactoryGirl.create(:forum_post, :topic_id => @topic.id) post = FactoryGirl.create(:forum_post, :topic_id => @topic.id)
@topic.reload @topic.reload
assert_not_equal(original_topic_updated_at, @topic.updated_at) assert_not_equal(@original_topic_updated_at, @topic.updated_at)
end end
should "be searchable by body content" do should "be searchable by body content" do