MS; DG; adding cucumbers for post templates
This commit is contained in:
parent
b1cbd0f4a9
commit
37981b71fe
7 changed files with 111 additions and 5 deletions
14
features/post_viewer.feature
Normal file
14
features/post_viewer.feature
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
@javascript
|
||||||
|
Feature: Post Viewer
|
||||||
|
In order to make my content look really great
|
||||||
|
As a User
|
||||||
|
I want my posts to have a bunch of different templates that I can page through
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given a user with email "alice@alice.com"
|
||||||
|
And I sign in as "alice@alice.com"
|
||||||
|
|
||||||
|
Scenario: Paging through posts
|
||||||
|
Given I have posts for each type of template
|
||||||
|
Then I visit all of my posts
|
||||||
|
And I should have seen all of my posts displayed with the correct template
|
||||||
11
features/step_definitions/template_steps.rb
Normal file
11
features/step_definitions/template_steps.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
Given /^I have posts for each type of template$/ do
|
||||||
|
generate_post_of_each_template(@me)
|
||||||
|
end
|
||||||
|
|
||||||
|
Then /^I visit all of my posts$/ do
|
||||||
|
@templates_seen = visit_posts_and_collect_template_names(@me)
|
||||||
|
end
|
||||||
|
|
||||||
|
When /^I should have seen all of my posts displayed with the correct template$/ do
|
||||||
|
@templates_seen.should =~ TemplatePicker.jsonified_templates
|
||||||
|
end
|
||||||
32
features/support/post_generation_helpers.rb
Normal file
32
features/support/post_generation_helpers.rb
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
module PostGenerationHelpers
|
||||||
|
|
||||||
|
def generate_post_of_each_template(user)
|
||||||
|
time = Time.now
|
||||||
|
|
||||||
|
TemplatePicker::TEMPLATES.each do |template|
|
||||||
|
Timecop.travel time += 1.minute
|
||||||
|
Factory(template, :author => user.person)
|
||||||
|
end
|
||||||
|
|
||||||
|
Timecop.return
|
||||||
|
end
|
||||||
|
|
||||||
|
def visit_posts_and_collect_template_names(user)
|
||||||
|
visit(post_path(user.posts.last))
|
||||||
|
user.posts.map do |post|
|
||||||
|
post = find('.post')
|
||||||
|
template_name = post['data-template']
|
||||||
|
click_next_button
|
||||||
|
template_name
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def click_next_button
|
||||||
|
next_arrow = '.nav-arrow.right'
|
||||||
|
if page.has_selector?(next_arrow)
|
||||||
|
find(next_arrow).click()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
World(PostGenerationHelpers)
|
||||||
|
|
@ -16,7 +16,7 @@ class TemplatePicker
|
||||||
|
|
||||||
def template_name
|
def template_name
|
||||||
TEMPLATES.each do |template|
|
TEMPLATES.each do |template|
|
||||||
return template.gsub("_", '-') if self.send("#{template}?".to_sym)
|
return TemplatePicker.jsonify_name(template) if self.send("#{template}?".to_sym)
|
||||||
end
|
end
|
||||||
|
|
||||||
'status' #default
|
'status' #default
|
||||||
|
|
@ -49,4 +49,12 @@ class TemplatePicker
|
||||||
def status?
|
def status?
|
||||||
post.text?
|
post.text?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.jsonified_templates
|
||||||
|
TEMPLATES.map{|x| jsonify_name(x)}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.jsonify_name(name)
|
||||||
|
name.gsub('_', '-')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -12,8 +12,9 @@ app.pages.PostViewer = app.views.Base.extend({
|
||||||
postView : function(){
|
postView : function(){
|
||||||
return new app.views.Post({
|
return new app.views.Post({
|
||||||
model : this.model,
|
model : this.model,
|
||||||
className : "loaded",
|
className : "post loaded",
|
||||||
templateName : "post-viewer/content/" + this.options.postTemplateName
|
templateName : "post-viewer/content/" + this.options.postTemplateName,
|
||||||
|
attributes : {"data-template" : this.options.postTemplateName}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -197,6 +197,11 @@ FactoryGirl.define do
|
||||||
name "partytimeexcellent"
|
name "partytimeexcellent"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory(:o_embed_cache) do
|
||||||
|
url "http://youtube.com/kittens"
|
||||||
|
data Hash.new('data' => "stuff").to_s
|
||||||
|
end
|
||||||
|
|
||||||
factory(:tag_following) do
|
factory(:tag_following) do
|
||||||
association(:tag, :factory => :tag)
|
association(:tag, :factory => :tag)
|
||||||
association(:user, :factory => :user)
|
association(:user, :factory => :user)
|
||||||
|
|
@ -211,4 +216,27 @@ FactoryGirl.define do
|
||||||
association(:person, :factory => :person)
|
association(:person, :factory => :person)
|
||||||
association(:post, :factory => :status_message)
|
association(:post, :factory => :status_message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#templates
|
||||||
|
factory(:multi_photo, :parent => :status_message_with_photo) do
|
||||||
|
after_build do |sm|
|
||||||
|
2.times{ Factory(:photo, :author => sm.author, :status_message => sm, :pending => false, :public => public)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
factory(:status_with_photo_backdrop, :parent => :status_message_with_photo)
|
||||||
|
|
||||||
|
factory(:photo_backdrop, :parent => :status_message_with_photo) do
|
||||||
|
text ""
|
||||||
|
end
|
||||||
|
|
||||||
|
factory(:note, :parent => :status_message) do
|
||||||
|
text ActiveSupport::SecureRandom.hex(1000)
|
||||||
|
end
|
||||||
|
|
||||||
|
factory(:rich_media, :parent => :status_message) do
|
||||||
|
association(:o_embed_cache)
|
||||||
|
end
|
||||||
|
|
||||||
|
factory(:status, :parent => :status_message)
|
||||||
end
|
end
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'template_picker')
|
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'template_picker')
|
||||||
|
require 'spec_helper'
|
||||||
describe TemplatePicker do
|
describe TemplatePicker do
|
||||||
before do
|
before do
|
||||||
@post_stubs = {:type => 'StatusMessage', :photos => stub(:size => 2),
|
@post_stubs = {:type => 'StatusMessage', :photos => stub(:size => 2),
|
||||||
|
|
@ -69,4 +69,16 @@ describe TemplatePicker do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'factories' do
|
||||||
|
TemplatePicker::TEMPLATES.each do |template|
|
||||||
|
describe "#{template} factory" do
|
||||||
|
it 'works' do
|
||||||
|
post = Factory(template.to_sym, :author => alice.person).reload
|
||||||
|
template_name = TemplatePicker.new(post).template_name.gsub('-', '_')
|
||||||
|
template_name.should == template
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
Loading…
Reference in a new issue