Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module HelperMethods
- def upload_track(options = {})
- case options
- when :mp3
- attachment = File.new(File.join(Rails.root, 'spec', 'support', 'files', 'track.mp3'))
- when :image
- attachment = File.new(File.join(Rails.root, 'spec', 'support', 'files', 'image.jpg'))
- end
- track = Track.upload(@user, attachment.to_path, attachment)
- end
- def destroy_from_collection(track, album)
- page.driver.delete("/album_collections/#{album.id}?album_id=#{album.id}&track_id=#{track.id}")
- visit page.driver.response.location
- end
- def create_album_collection(count, user, album)
- count.times { Factory.create(:album_collection, :track => Factory.create(:track, :user => user), :album => album)}
- end
- def remote_ip_digest
- Digest::SHA1.hexdigest("request.remote_addr")
- end
- def generate_authorize_key
- Digest::SHA1.hexdigest("#{Time.now.strftime("%H%M")}#{remote_ip_digest}")
- end
- def authorize_track
- cookies[:authorize_track] = generate_authorize_key
- end
- def fill_user_form(name, email, password = 'foobar', confirmation = false)
- (fill_in 'Name', :with => name) if name.present?
- (fill_in "Email", :with => email) if email.present?
- (fill_in "Password", :with => password) if password.present?
- (fill_in "Password confirmation", :with => password) if confirmation == true
- end
- def sign_in(email = nil, password = nil)
- @user = Factory(:user)
- visit root_path
- click_link "Sign in"
- fill_user_form(nil, (email.blank? ? @user.email : email), (password.blank? ? 'foobar' : password))
- click_button "Sign In"
- end
- def page_should_have(array)
- array.map {|album| page.should have_content album.title}
- end
- def truncate_title(album, length)
- title = album.title
- title = title.chop while title.length > (length - 3)
- split = title.split.delete_if {|word| !album.title.split.include?(word) if title.split.last.length > 3}
- return "#{split.join(" ")}..."
- end
- def start_new_album(options = {:title => false, :image => false}, album = false)
- unless album
- visit new_album_path
- else
- visit edit_album_path(album)
- end
- fill_in "Title", :with => (options[:title] ? 'Album collection' : '')
- case options[:image]
- when :medium
- attach_file('Cover', 'spec/support/files/image.jpg')
- when :small
- attach_file('Cover', 'spec/support/files/small_image.jpg')
- when :not_image
- attach_file('Cover', 'spec/support/files/track.mp3')
- end
- yield if block_given?
- click_button (album ? 'Update Album' : 'Create Album')
- end
- end
- RSpec.configuration.include HelperMethods
Add Comment
Please, Sign In to add comment