From f64f12d646936412e7fb4c28186f2cc7e568d2c6 Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion)" Date: Wed, 17 Aug 2011 20:33:38 +0200 Subject: [PATCH] Continue developing --- Gemfile | 4 ++ Gemfile.lock | 11 ++++ Guardfile | 11 ++++ app/assets/stylesheets/application.css.scss | 51 +++++++++++++++++++ app/controllers/admin/dashboard_controller.rb | 4 ++ app/controllers/admin/sites_controller.rb | 16 +++--- app/controllers/test_controller.rb | 11 ++++ app/helpers/test_helper.rb | 2 + app/views/admin/dashboard/new_site.html.erb | 30 +++++++++-- app/views/admin/sites/created.html.erb | 2 + config/routes.rb | 8 ++- spec/controllers/test_controller_spec.rb | 5 ++ spec/factories.rb | 6 ++- spec/helpers/test_helper_spec.rb | 15 ++++++ spec/requests/admin/dashboard_spec.rb | 15 ++++-- spec/requests/admin/sites_spec.rb | 19 ++++++- spec/support/spec_support.rb | 3 +- 17 files changed, 193 insertions(+), 20 deletions(-) create mode 100644 Guardfile create mode 100644 app/controllers/test_controller.rb create mode 100644 app/helpers/test_helper.rb create mode 100644 app/views/admin/sites/created.html.erb create mode 100644 spec/controllers/test_controller_spec.rb create mode 100644 spec/helpers/test_helper_spec.rb diff --git a/Gemfile b/Gemfile index 704d5009..f8ec0ef8 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,10 @@ gem 'coffee-script' # To use debugger # gem 'ruby-debug' +group :development do + gem 'guard-livereload' +end + # Bundle gems for the local environment. Make sure to # put test-only gems in this group so their generators # and rake tasks are available in development mode: diff --git a/Gemfile.lock b/Gemfile.lock index f90762ff..1bdd3329 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -62,7 +62,11 @@ GEM orm_adapter (~> 0.0.3) warden (~> 1.0.3) diff-lcs (1.1.2) + em-websocket (0.3.1) + addressable (>= 2.1.1) + eventmachine (>= 0.12.9) erubis (2.7.0) + eventmachine (0.12.10) execjs (1.2.4) multi_json (~> 1.0) factory_girl (2.0.4) @@ -70,6 +74,12 @@ GEM factory_girl (~> 2.0.0) railties (>= 3.0.0) ffi (1.0.9) + guard (0.6.2) + thor (~> 0.14.6) + guard-livereload (0.3.0) + em-websocket (>= 0.2.0) + guard (>= 0.4.0) + multi_json (~> 1.0.3) hike (1.2.0) i18n (0.6.0) jquery-rails (1.0.13) @@ -174,6 +184,7 @@ DEPENDENCIES default_value_for devise factory_girl_rails + guard-livereload jquery-rails (>= 1.0.12) launchy rails (= 3.1.0.rc5) diff --git a/Guardfile b/Guardfile new file mode 100644 index 00000000..2e2fa4ed --- /dev/null +++ b/Guardfile @@ -0,0 +1,11 @@ +# A sample Guardfile +# More info at https://github.com/guard/guard#readme + +guard 'livereload' do + watch(%r{app/.+\.(erb|js)}) + watch(%r{app/helpers/.+\.rb}) + watch(%r{(public/|app/assets).+\.(css|js|html)}) + watch(%r{(app/assets/.+\.css)\.s[ac]ss}) { |m| m[1] } + watch(%r{(app/assets/.+\.js)\.coffee}) { |m| m[1] } + watch(%r{config/locales/.+\.yml}) +end diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index d0e3d6c8..091d8a2c 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -45,6 +45,28 @@ textarea { height: 200px; } +input[type="text"] { + background: rgb(232,232,232); /* Old browsers */ + background: -moz-linear-gradient(top, rgba(232,232,232,1) 0%, rgba(255,255,255,1) 40%, rgba(255,255,255,1) 100%); /* FF3.6+ */ + background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(232,232,232,1)), color-stop(40%,rgba(255,255,255,1)), color-stop(100%,rgba(255,255,255,1))); /* Chrome,Safari4+ */ + background: -webkit-linear-gradient(top, rgba(232,232,232,1) 0%,rgba(255,255,255,1) 40%,rgba(255,255,255,1) 100%); /* Chrome10+,Safari5.1+ */ + background: -o-linear-gradient(top, rgba(232,232,232,1) 0%,rgba(255,255,255,1) 40%,rgba(255,255,255,1) 100%); /* Opera11.10+ */ + background: -ms-linear-gradient(top, rgba(232,232,232,1) 0%,rgba(255,255,255,1) 40%,rgba(255,255,255,1) 100%); /* IE10+ */ + filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e8e8e8', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */ + background: linear-gradient(top, rgba(232,232,232,1) 0%,rgba(255,255,255,1) 40%,rgba(255,255,255,1) 100%); /* W3C */ + + border: 1px solid #aaaaaa; + padding: 4px; + font-size: 0.85em; + @include BorderRadius(4px); + @include BoxShadow(0px 0px 1px gray); +} + +input[type="submit"] { + font-size: 0.85em; + padding: 6px 12px 6px 12px; +} + #sections_bar { margin: 20px; @@ -245,6 +267,35 @@ form.comment { } } +form.new_site { + p { + margin-top: 0.25em; + margin-bottom: 0.25em; + } + + label { + display: block; + } + + input[type="text"] { + width: 30em; + } + + .field { + margin-top: 1em; + margin-bottom: 1em; + } + + .desc { + font-size: 120%; + font-weight: bold; + } + + .radio_buttons { + margin-left: 8px; + } +} + /* _______________________________ diff --git a/app/controllers/admin/dashboard_controller.rb b/app/controllers/admin/dashboard_controller.rb index 9602b05b..8fba58ea 100644 --- a/app/controllers/admin/dashboard_controller.rb +++ b/app/controllers/admin/dashboard_controller.rb @@ -23,6 +23,10 @@ def new_admin def create_admin #raise if User.where(:admin => true).count > 0 end + + def new_site + @site = Site.new + end private def set_navigation_ids diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index 9179f600..bdaed386 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -1,7 +1,6 @@ class Admin::SitesController < ApplicationController layout 'admin' - before_filter :require_admin! before_filter :set_navigation_ids # GET /admin/sites @@ -45,14 +44,15 @@ def edit # POST /admin/sites # POST /admin/sites.json def create - @site = Site.new(params[:admin_site]) + @site = Site.new(params[:site]) + @site.user = current_user respond_to do |format| if @site.save - format.html { redirect_to @site, :notice => 'Site was successfully created.' } + format.html { redirect_to created_admin_site_path(@site) } format.json { render :json => @site, :status => :created, :location => @site } else - format.html { render action: "new" } + format.html { render :action => "new" } format.json { render :json => @site.errors, :status => :unprocessable_entity } end end @@ -64,11 +64,11 @@ def update @site = Site.find(params[:id]) respond_to do |format| - if @site.update_attributes(params[:admin_site]) - format.html { redirect_to @site, :notice => 'Site was successfully updated.' } + if @site.update_attributes(params[:site]) + format.html { redirect_to [:admin, @site], :notice => 'Site was successfully updated.' } format.json { head :ok } else - format.html { render action: "edit" } + format.html { render :action => "edit" } format.json { render :json => @site.errors, :status => :unprocessable_entity } end end @@ -81,7 +81,7 @@ def destroy @site.destroy respond_to do |format| - format.html { redirect_to admin_sites_url } + format.html { redirect_to admin_sites_path } format.json { head :ok } end end diff --git a/app/controllers/test_controller.rb b/app/controllers/test_controller.rb new file mode 100644 index 00000000..04a1f3c3 --- /dev/null +++ b/app/controllers/test_controller.rb @@ -0,0 +1,11 @@ +class TestController < ApplicationController + layout nil + + skip_before_filter :verify_authenticity_token + skip_before_filter :authenticate_user! + + def login + sign_in(User.find(params[:user_id])) + render :text => 'ok' + end +end if Rails.env.test? diff --git a/app/helpers/test_helper.rb b/app/helpers/test_helper.rb new file mode 100644 index 00000000..09b6d50b --- /dev/null +++ b/app/helpers/test_helper.rb @@ -0,0 +1,2 @@ +module TestHelper +end diff --git a/app/views/admin/dashboard/new_site.html.erb b/app/views/admin/dashboard/new_site.html.erb index 3d049a36..cb24f9ba 100644 --- a/app/views/admin/dashboard/new_site.html.erb +++ b/app/views/admin/dashboard/new_site.html.erb @@ -2,6 +2,30 @@

Let's get started!

So you want to embed comments on a bunch of web pages.

-

What's your site's name? Just enter one. If you have more you can add them later.

- -

How do you want to moderate new comments?

+<%= form_for([:admin, @site], :class => 'new_site') do |f| %> +
+

+

Enter just one. If you have more you can add them later.

+ <%= f.text_field :name %> +
+ +
+

How do you want to moderate new comments?

+
+ + + +
+
+ + <%= f.submit 'Next step »'.html_safe %> +<% end %> diff --git a/app/views/admin/sites/created.html.erb b/app/views/admin/sites/created.html.erb new file mode 100644 index 00000000..a74f1cf1 --- /dev/null +++ b/app/views/admin/sites/created.html.erb @@ -0,0 +1,2 @@ +

Your site has been created!

+Here's how you embed comments in your web pages. diff --git a/config/routes.rb b/config/routes.rb index 1f69822a..d8a7556b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,12 @@ get :preview end end - resources :sites + resources :sites do + member do + get :created + get :install + end + end resources :users do get :comments get :sites @@ -18,6 +23,7 @@ end match 'admin/dashboard(/:action)', :to => 'admin/dashboard', :as => :dashboard + match 'test/:action', :to => 'test' if Rails.env.test? # The priority is based upon order of creation: # first created -> highest priority. diff --git a/spec/controllers/test_controller_spec.rb b/spec/controllers/test_controller_spec.rb new file mode 100644 index 00000000..b7dbfcd6 --- /dev/null +++ b/spec/controllers/test_controller_spec.rb @@ -0,0 +1,5 @@ +require 'spec_helper' + +describe TestController do + +end diff --git a/spec/factories.rb b/spec/factories.rb index 99047009..5a6d6977 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -3,7 +3,7 @@ email 'admin@admin.com' password 123456 password_confirmation 123456 - is_admin true + admin true end factory :kotori, :class => User do @@ -58,6 +58,10 @@ end module FactoryHelpers + def admin(attrs = {}) + @admin ||= FactoryGirl.create(:admin, attrs) + end + def kotori(attrs = {}) @kotori ||= FactoryGirl.create(:kotori, attrs) end diff --git a/spec/helpers/test_helper_spec.rb b/spec/helpers/test_helper_spec.rb new file mode 100644 index 00000000..0785ef51 --- /dev/null +++ b/spec/helpers/test_helper_spec.rb @@ -0,0 +1,15 @@ +require 'spec_helper' + +# Specs in this file have access to a helper object that includes +# the TestHelper. For example: +# +# describe TestHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# helper.concat_strings("this","that").should == "this that" +# end +# end +# end +describe TestHelper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/admin/dashboard_spec.rb b/spec/requests/admin/dashboard_spec.rb index 6a624ca6..301611a6 100644 --- a/spec/requests/admin/dashboard_spec.rb +++ b/spec/requests/admin/dashboard_spec.rb @@ -1,3 +1,4 @@ +# encoding: utf-8 require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") describe "Admin::Dashboard" do @@ -12,18 +13,22 @@ end describe "setting up a site" do - it "works" do + before :each do + login(admin) visit '/admin/dashboard/new_site' + end + + it "works" do page.should have_content("So you want to embed comments on a bunch of web pages") fill_in 'site[name]', :with => 'Foo' - fill_in 'site[moderation_type]' - click_button 'Next step »' - page.should have_content("Your site has been created. Here's how you embed comments in your web pages.") + choose 'Manually approve all comments.' + click_button 'Next step »' + page.should have_content("Your site has been created! Here's how you embed comments in your web pages.") Site.find_by_name('Foo').should_not be_nil end it "refuses to create the site upon errors" do - click_button 'Next step »' + click_button 'Next step »' page.should have_content("prohibited this site from being created") page.should have_content("So you want to embed comments on a bunch of web pages") end diff --git a/spec/requests/admin/sites_spec.rb b/spec/requests/admin/sites_spec.rb index 92cb1370..3c0b3b54 100644 --- a/spec/requests/admin/sites_spec.rb +++ b/spec/requests/admin/sites_spec.rb @@ -1,8 +1,25 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper") describe "Admin::Sites" do - describe "GET /admin/sites" do + describe "/admin/sites" do it "shows all sites that the current user can access" it "shows the sites alphabetically" end + + describe "/admin/sites/:id" do + it "shows the most recent comments" + end + + describe "/admin/sites/:id/topics" do + it "shows the most recent topics" + end + + describe "installation page" do + it "shows installation instructions" + end + + describe "settings page" do + it "shows the site settings" + it "allows updating the site settings" + end end diff --git a/spec/support/spec_support.rb b/spec/support/spec_support.rb index 3e8a0f44..6c2d16c2 100644 --- a/spec/support/spec_support.rb +++ b/spec/support/spec_support.rb @@ -1,7 +1,8 @@ module SpecSupport def login(user) if example.metadata[:type] == :request - raise "Not yet implemented" + visit("/test/login?user_id=#{user.id}") + page.should have_content("ok") elsif example.metadata[:type] == :controller raise "Please use sign_in instead in controller specs" else