This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a625e0
commit 44a1c6b
Showing
3 changed files
with
157 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Feature: Regenerating styles | ||
|
||
Scenario: Adding a new style | ||
Given I generate a new rails application | ||
And I have made a simple avatar on the user model | ||
And I start the rails application | ||
And I upload an avatar to the user model | ||
When I add the following style to the user avatar: | ||
""" | ||
large: '124x124#' | ||
""" | ||
And I change the user show page to show the large avatar | ||
Then I see a missing large avatar on the user show page | ||
When I generate the "add_large_thumbnail_to_user_avatar" migration as follows: | ||
""" | ||
def up | ||
add_style :users, :avatar, large: '124x124#' | ||
end | ||
def down | ||
remove_style :users, :avatar, :large | ||
end | ||
""" | ||
And I run the up database migration | ||
Then I see the large avatar on the user show page | ||
When I run the down database migration | ||
Then I see a missing large avatar on the user show page | ||
|
||
Scenario: Changing an existing style | ||
Given I generate a new rails application | ||
And I have made the following avatar style on the user model: | ||
""" | ||
thumbnail: '32x32' | ||
""" | ||
And I upload an avatar to the user model | ||
When I change the avatar style on the user model to: | ||
""" | ||
thumbnail: '16x16' | ||
""" | ||
Then I see a "32x32" thumbnail avatar on the user show page | ||
When I generate the "change_user_avatar_thumbnail_size" migration | ||
And the "up" migration for "change_user_avatar_thumbnail_size" is: | ||
""" | ||
change_style :users, :avatar, thumbnail: '16x16' | ||
""" | ||
And the "down" migration for "change_user_avatar_thumbnail_size" is: | ||
""" | ||
change_style :users, :avatar, thumbnail: '32x32' | ||
""" | ||
And I run the up database migration | ||
Then I see a "16x16" thumbnail avatar on the user show page | ||
When I run the down database migration | ||
Then I see a "32x32" thumbnail avatar on the user show page |
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,88 @@ | ||
Given /^I have made a simple avatar on the user model$/ do | ||
run_simple(%{bundle exec #{generator_command} scaffold user}) | ||
run_simple(%{bundle exec #{generator_command} paperclip user avatar}) | ||
run_simple(%{bundle exec rake db:migrate}) | ||
write_file('app/views/users/new.html.erb', <<-VIEW) | ||
<%= form_for @user, :html => { :multipart => true } do |f| %> | ||
<%= f.label :avatar %> | ||
<%= f.file_field :avatar %> | ||
<%= submit_tag 'Submit' %> | ||
<% end %> | ||
VIEW | ||
write_file('app/views/users/show.html.erb', <<-VIEW) | ||
<p>Attachment: <%= image_tag @user.avatar.url(:thumbnail) %></p> | ||
VIEW | ||
write_file('app/models/user.rb', <<-MODEL) | ||
class User < ActiveRecord::Base | ||
has_attached_file :avatar, styles: { thumbnail: '8x8#' } | ||
attr_accessible :avatar | ||
end | ||
MODEL | ||
end | ||
|
||
Given /^I upload an avatar to the user model$/ do | ||
visit '/users/new' | ||
attach_file('Avatar', File.expand_path('test/fixtures/5k.png')) | ||
click_button 'Submit' | ||
end | ||
|
||
When /^I add the following style to the user avatar:$/ do |string| | ||
write_file('app/models/user.rb', <<-MODEL) | ||
class User < ActiveRecord::Base | ||
has_attached_file :avatar, styles: { thumbnail: '8x8#', #{string} } | ||
attr_accessible :avatar | ||
end | ||
MODEL | ||
end | ||
|
||
When /^I change the user show page to show the large avatar$/ do | ||
write_file('app/views/users/show.html.erb', <<-VIEW) | ||
<p>Attachment: <%= image_tag @user.avatar.url(:large) %></p> | ||
VIEW | ||
end | ||
|
||
Then /^I see a missing large avatar on the user show page$/ do | ||
user = User.last | ||
user.should_not be_nil | ||
visit "/users/#{user.to_param}" | ||
|
||
page.source =~ %r{img alt="5k" src="([^"]+)?.*"} | ||
image_path = $1 | ||
image_path.should_not be_blank | ||
|
||
File.should_not be_exist(Rails.root.join('public',image_path)) | ||
end | ||
|
||
When /^I generate the "(.*?)" migration as follows:$/ do |migration_name, code| | ||
run_simple(%{bundle exec ./script/rails generate migration #{migration_name}}) | ||
migration_filename = Dir[Rails.root.join('db', 'migrate', "*#{migration_name}.rb")].first | ||
write_file(migration_filename, <<-MIGRATION) | ||
class #{migration_name.classify} < ActiveRecord::Migration | ||
#{code} | ||
end | ||
MIGRATION | ||
end | ||
|
||
When /^I run the up database migration$/ do | ||
run_simple('bundle exec rake db:migrate') | ||
end | ||
|
||
When /^I run the down database migration$/ do | ||
migration_filename = Dir[Rails.root.join('db', 'migrate', '*')].last | ||
migration_filename =~ %r{.*/(\d+)_[^/]+.rb} | ||
version = $1 | ||
version.should_not be_blank | ||
run_simple("bundle exec rake db:migrate:down VERSION=#{version}") | ||
end | ||
|
||
Then /^I see the large avatar on the user show page$/ do | ||
user = User.last | ||
user.should_not be_nil | ||
visit "/users/#{user.to_param}" | ||
|
||
page.source =~ %r{img alt="5k" src="([^"]+)?.*"} | ||
image_path = $1 | ||
image_path.should_not be_blank | ||
|
||
File.should be_exist(Rails.root.join('public',image_path)) | ||
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