diff --git a/features/post_viewer.feature b/features/post_viewer.feature new file mode 100644 index 000000000..8969a99f6 --- /dev/null +++ b/features/post_viewer.feature @@ -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 diff --git a/features/step_definitions/template_steps.rb b/features/step_definitions/template_steps.rb new file mode 100644 index 000000000..b58be5d67 --- /dev/null +++ b/features/step_definitions/template_steps.rb @@ -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 \ No newline at end of file diff --git a/features/support/post_generation_helpers.rb b/features/support/post_generation_helpers.rb new file mode 100644 index 000000000..27c671c2e --- /dev/null +++ b/features/support/post_generation_helpers.rb @@ -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) diff --git a/lib/template_picker.rb b/lib/template_picker.rb index 933ca458e..688c90a08 100644 --- a/lib/template_picker.rb +++ b/lib/template_picker.rb @@ -16,7 +16,7 @@ class TemplatePicker def template_name 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 'status' #default @@ -49,4 +49,12 @@ class TemplatePicker def status? post.text? end + + def self.jsonified_templates + TEMPLATES.map{|x| jsonify_name(x)} + end + + def self.jsonify_name(name) + name.gsub('_', '-') + end end \ No newline at end of file diff --git a/public/javascripts/app/pages/post-viewer.js b/public/javascripts/app/pages/post-viewer.js index 740dbbf4e..61cd0a0bc 100644 --- a/public/javascripts/app/pages/post-viewer.js +++ b/public/javascripts/app/pages/post-viewer.js @@ -12,8 +12,9 @@ app.pages.PostViewer = app.views.Base.extend({ postView : function(){ return new app.views.Post({ model : this.model, - className : "loaded", - templateName : "post-viewer/content/" + this.options.postTemplateName + className : "post loaded", + templateName : "post-viewer/content/" + this.options.postTemplateName, + attributes : {"data-template" : this.options.postTemplateName} }) }, diff --git a/spec/factories.rb b/spec/factories.rb index 3526097cf..7057c21bd 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -197,6 +197,11 @@ FactoryGirl.define do name "partytimeexcellent" end + factory(:o_embed_cache) do + url "http://youtube.com/kittens" + data Hash.new('data' => "stuff").to_s + end + factory(:tag_following) do association(:tag, :factory => :tag) association(:user, :factory => :user) @@ -211,4 +216,27 @@ FactoryGirl.define do association(:person, :factory => :person) 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 \ No newline at end of file diff --git a/spec/lib/template_picker_spec.rb b/spec/lib/template_picker_spec.rb index df9b51163..0ef0adabb 100644 --- a/spec/lib/template_picker_spec.rb +++ b/spec/lib/template_picker_spec.rb @@ -1,5 +1,5 @@ require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'template_picker') - +require 'spec_helper' describe TemplatePicker do before do @post_stubs = {:type => 'StatusMessage', :photos => stub(:size => 2), @@ -69,4 +69,16 @@ describe TemplatePicker do 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 \ No newline at end of file