Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: tonycoco/gallery
base: ac7fdf1946
...
head fork: tonycoco/gallery
compare: ee2077f00d
Checking mergeability… Don't worry, you can still create the pull request.
  • 6 commits
  • 54 files changed
  • 0 commit comments
  • 1 contributor
Showing with 1,133 additions and 134 deletions.
  1. +35 −35 Gemfile
  2. +48 −63 Gemfile.lock
  3. +14 −8 app/assets/javascripts/jquery.validate.bootstrap.js
  4. +3 −0  app/assets/javascripts/photo_sets.js.coffee
  5. +3 −0  app/assets/javascripts/photos.js.coffee
  6. +10 −1 app/assets/stylesheets/{_welcome.css.scss → _pages.css.scss}
  7. +1 −1  app/assets/stylesheets/layout.css.scss
  8. +3 −0  app/assets/stylesheets/photo_sets.css.scss
  9. +3 −0  app/assets/stylesheets/photos.css.scss
  10. +7 −0 app/controllers/admin_controller.rb
  11. +4 −0 app/controllers/application_controller.rb
  12. +7 −0 app/controllers/pages_controller.rb
  13. +83 −0 app/controllers/photo_sets_controller.rb
  14. +86 −0 app/controllers/photos_controller.rb
  15. +0 −9 app/controllers/welcome_controller.rb
  16. +2 −0  app/helpers/photo_sets_helper.rb
  17. +2 −0  app/helpers/photos_helper.rb
  18. +7 −8 app/models/ability.rb
  19. +10 −0 app/models/photo.rb
  20. +6 −0 app/models/photo_set.rb
  21. +5 −1 app/models/user.rb
  22. +0 −2  app/uploaders/avatar_uploader.rb
  23. +49 −0 app/uploaders/photo_uploader.rb
  24. +17 −0 app/views/admin/index.html.haml
  25. +0 −1  app/views/devise/registrations/new.html.haml
  26. +0 −1  app/views/devise/sessions/new.html.haml
  27. +5 −0 app/views/pages/contact.html.haml
  28. 0  app/views/{welcome/index.html.haml → pages/welcome.html.haml}
  29. +9 −0 app/views/photo_sets/_form.html.haml
  30. +43 −0 app/views/photo_sets/edit.html.haml
  31. +36 −0 app/views/photo_sets/index.html.haml
  32. +19 −0 app/views/photo_sets/new.html.haml
  33. +31 −0 app/views/photo_sets/show.html.haml
  34. +10 −0 app/views/photos/_form.html.haml
  35. +20 −0 app/views/photos/edit.html.haml
  36. +19 −0 app/views/photos/new.html.haml
  37. +21 −0 app/views/photos/show.html.haml
  38. +15 −0 app/views/shared/_navbar.html.haml
  39. +1 −1  config/application.yml
  40. +10 −2 config/routes.rb
  41. +10 −0 db/migrate/20120416161734_create_photo_sets.rb
  42. +12 −0 db/migrate/20120416161925_create_photos.rb
  43. +17 −1 db/schema.rb
  44. +3 −0  db/seeds.rb
  45. +164 −0 spec/controllers/photo_sets_controller_spec.rb
  46. +164 −0 spec/controllers/photos_controller_spec.rb
  47. +8 −0 spec/factories/photo_sets.rb
  48. +9 −0 spec/factories/photos.rb
  49. +5 −0 spec/models/photo_set_spec.rb
  50. +5 −0 spec/models/photo_spec.rb
  51. +11 −0 spec/requests/photo_sets_spec.rb
  52. +11 −0 spec/requests/photos_spec.rb
  53. +35 −0 spec/routing/photo_sets_routing_spec.rb
  54. +35 −0 spec/routing/photos_routing_spec.rb
View
70 Gemfile
@@ -7,7 +7,6 @@ gem 'rails', '3.2.2'
gem 'mysql2'
-
# Gems used only for assets and not required
# in production environments by default.
group :assets do
@@ -37,48 +36,49 @@ gem 'jquery-rails'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
-gem "bootstrap-sass", :git => "git://github.com/thomas-mcdonald/bootstrap-sass"
-gem "bootstrap_kaminari", :git => "git://github.com/tonycoco/bootstrap_kaminari.git"
-gem "carrierwave"
-gem "devise"
-gem "fog"
-gem "haml-rails"
-gem "kaminari", :git => "git://github.com/amatsuda/kaminari.git"
-gem "mini_magick"
-gem "omniauth"
-gem "omniauth-facebook"
-gem "omniauth-twitter"
-gem "resque", :require => "resque/server"
-gem "settingslogic"
-gem "simple_form", :git => "git://github.com/plataformatec/simple_form.git"
-gem "cancan"
+gem 'bootstrap-sass'
+gem 'bootstrap_kaminari', :git => 'git://github.com/tonycoco/bootstrap_kaminari.git'
+gem 'carrierwave'
+gem 'devise'
+gem 'fog'
+gem 'haml-rails'
+gem 'kaminari'
+gem 'mini_magick'
+gem 'omniauth'
+gem 'omniauth-facebook'
+gem 'omniauth-twitter'
+gem 'resque', :require => 'resque/server'
+gem 'settingslogic'
+gem 'simple_form'
+gem 'cancan'
+
group :development do
- gem "capistrano"
- gem "foreman"
- gem "rails-footnotes"
- gem "ruby-debug19", :require => "ruby-debug"
- gem "taps"
- gem "added_methods"
- gem "awesome_print"
- gem "brice"
- gem "looksee"
- gem "what_methods"
+ gem 'capistrano'
+ gem 'foreman'
+ gem 'rails-footnotes'
+ gem 'ruby-debug19', :require => 'ruby-debug'
+ gem 'taps'
+ gem 'added_methods'
+ gem 'awesome_print'
+ gem 'brice'
+ gem 'looksee'
+ gem 'what_methods'
end
group :development, :test do
- gem "mysql2"
- gem "rspec-rails"
- gem "syntax"
+ gem 'mysql2'
+ gem 'rspec-rails'
+ gem 'syntax'
end
group :test do
- gem "capybara"
- gem "cucumber-rails"
- gem "database_cleaner"
- gem "factory_girl_rails"
+ gem 'capybara'
+ gem 'cucumber-rails'
+ gem 'database_cleaner'
+ gem 'factory_girl_rails'
end
group :production do
- gem "pg"
- gem "thin"
+ gem 'pg'
+ gem 'thin'
end
View
111 Gemfile.lock
@@ -1,27 +1,4 @@
GIT
- remote: git://github.com/amatsuda/kaminari.git
- revision: 118927a42e57d6608c10d85b8a62acfc7c175974
- specs:
- kaminari (0.13.0)
- actionpack (>= 3.0.0)
- activesupport (>= 3.0.0)
- railties (>= 3.0.0)
-
-GIT
- remote: git://github.com/plataformatec/simple_form.git
- revision: 51f680a9a2233748669655d81c82f96bef775298
- specs:
- simple_form (2.0.2.dev)
- actionpack (~> 3.0)
- activemodel (~> 3.0)
-
-GIT
- remote: git://github.com/thomas-mcdonald/bootstrap-sass
- revision: f71cf6e63cf5bde4ad12a088bbc0dc0e0434a000
- specs:
- bootstrap-sass (2.0.1)
-
-GIT
remote: git://github.com/tonycoco/bootstrap_kaminari.git
revision: cd05cc79c1afea783d84e2253cd7988ed2555fad
specs:
@@ -65,11 +42,12 @@ GEM
arel (3.0.2)
awesome_print (1.0.2)
bcrypt-ruby (3.0.1)
+ bootstrap-sass (2.0.2)
brice (0.2.4)
ruby-nuggets (>= 0.5.2)
builder (3.0.0)
cancan (1.6.7)
- capistrano (2.11.2)
+ capistrano (2.12.0)
highline
net-scp (>= 1.0.0)
net-sftp (>= 2.0.0)
@@ -82,10 +60,10 @@ GEM
rack-test (>= 0.5.4)
selenium-webdriver (~> 2.0)
xpath (~> 0.1.4)
- carrierwave (0.6.0)
+ carrierwave (0.6.2)
activemodel (>= 3.2.0)
activesupport (>= 3.2.0)
- childprocess (0.3.1)
+ childprocess (0.3.2)
ffi (~> 1.0.6)
coffee-rails (3.2.2)
coffee-script (>= 2.2.0)
@@ -93,7 +71,7 @@ GEM
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.2.0)
+ coffee-script-source (1.3.1)
columnize (0.3.6)
cucumber (1.1.9)
builder (>= 2.1.2)
@@ -115,18 +93,16 @@ GEM
diff-lcs (1.1.3)
erubis (2.7.0)
eventmachine (0.12.10)
- excon (0.13.2)
- execjs (1.3.0)
+ excon (0.13.4)
+ execjs (1.3.1)
multi_json (~> 1.0)
- factory_girl (3.0.0)
+ factory_girl (3.2.0)
activesupport (>= 3.0.0)
- factory_girl_rails (3.0.0)
- factory_girl (~> 3.0.0)
+ factory_girl_rails (3.2.0)
+ factory_girl (~> 3.2.0)
railties (>= 3.0.0)
- faraday (0.7.6)
- addressable (~> 2.2)
+ faraday (0.8.0)
multipart-post (~> 1.1)
- rack (~> 1.1)
ffi (1.0.11)
fog (1.3.1)
builder
@@ -138,7 +114,7 @@ GEM
net-ssh (>= 2.1.3)
nokogiri (~> 1.5.0)
ruby-hmac
- foreman (0.41.0)
+ foreman (0.45.0)
thor (>= 0.13.6)
formatador (0.2.1)
gherkin (2.9.3)
@@ -152,12 +128,19 @@ GEM
hashie (1.2.0)
highline (1.6.11)
hike (1.2.1)
+ httpauth (0.1)
i18n (0.6.0)
journey (1.0.3)
- jquery-rails (2.0.1)
+ jquery-rails (2.0.2)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
- json (1.6.6)
+ json (1.7.0)
+ kaminari (0.13.0)
+ actionpack (>= 3.0.0)
+ activesupport (>= 3.0.0)
+ railties (>= 3.0.0)
+ libwebsocket (0.1.3)
+ addressable
linecache19 (0.5.13)
ruby_core_source (>= 0.1.4)
looksee (1.0.3)
@@ -168,7 +151,7 @@ GEM
mime-types (1.18)
mini_magick (3.4)
subexec (~> 0.2.1)
- multi_json (1.2.0)
+ multi_json (1.3.4)
multipart-post (1.1.5)
mysql2 (0.3.11)
net-scp (1.0.4)
@@ -179,11 +162,12 @@ GEM
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
nokogiri (1.5.2)
- oauth (0.4.5)
- oauth2 (0.5.2)
+ oauth (0.4.6)
+ oauth2 (0.6.1)
faraday (~> 0.7)
- multi_json (~> 1.0)
- omniauth (1.0.3)
+ httpauth (~> 0.1)
+ multi_json (~> 1.3)
+ omniauth (1.1.0)
hashie (~> 1.2)
rack
omniauth-facebook (1.2.0)
@@ -191,10 +175,11 @@ GEM
omniauth-oauth (1.0.1)
oauth
omniauth (~> 1.0)
- omniauth-oauth2 (1.0.0)
- oauth2 (~> 0.5.0)
+ omniauth-oauth2 (1.0.2)
+ oauth2 (~> 0.6.0)
omniauth (~> 1.0)
- omniauth-twitter (0.0.9)
+ omniauth-twitter (0.0.11)
+ multi_json (~> 1.3)
omniauth-oauth (~> 1.0)
orm_adapter (0.0.7)
pg (0.13.2)
@@ -214,7 +199,7 @@ GEM
activesupport (= 3.2.2)
bundler (~> 1.0)
railties (= 3.2.2)
- rails-footnotes (3.7.6)
+ rails-footnotes (3.7.8)
rails (>= 3.0.0)
railties (3.2.2)
actionpack (= 3.2.2)
@@ -241,7 +226,7 @@ GEM
rspec-expectations (~> 2.9.0)
rspec-mocks (~> 2.9.0)
rspec-core (2.9.0)
- rspec-expectations (2.9.0)
+ rspec-expectations (2.9.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
rspec-rails (2.9.0)
@@ -258,39 +243,39 @@ GEM
linecache19 (>= 0.5.11)
ruby-debug-base19 (>= 0.11.19)
ruby-hmac (0.4.0)
- ruby-nuggets (0.8.5)
+ ruby-nuggets (0.8.7)
ruby_core_source (0.1.5)
archive-tar-minitar (>= 0.5.2)
- rubyzip (0.9.6.1)
- sass (3.1.15)
+ rubyzip (0.9.8)
+ sass (3.1.16)
sass-rails (3.2.5)
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
- selenium-webdriver (2.20.0)
+ selenium-webdriver (2.21.2)
childprocess (>= 0.2.5)
ffi (~> 1.0)
+ libwebsocket (~> 0.1.3)
multi_json (~> 1.0)
rubyzip
sequel (3.20.0)
settingslogic (2.0.8)
+ simple_form (2.0.2)
+ actionpack (~> 3.0)
+ activemodel (~> 3.0)
sinatra (1.0)
rack (>= 1.0)
- sprockets (2.1.2)
+ sprockets (2.1.3)
hike (~> 1.2)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
- sqlite3 (1.3.5)
- sqlite3-ruby (1.3.3)
- sqlite3 (>= 1.3.3)
- subexec (0.2.1)
+ subexec (0.2.2)
syntax (1.0.0)
- taps (0.3.23)
+ taps (0.3.24)
rack (>= 1.0.1)
rest-client (>= 1.4.0, < 1.7.0)
sequel (~> 3.20.0)
sinatra (~> 1.0.0)
- sqlite3-ruby (~> 1.2)
term-ansicolor (1.0.7)
thin (1.3.1)
daemons (>= 1.0.9)
@@ -301,7 +286,7 @@ GEM
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
- tzinfo (0.3.32)
+ tzinfo (0.3.33)
uglifier (1.2.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
@@ -319,7 +304,7 @@ PLATFORMS
DEPENDENCIES
added_methods
awesome_print
- bootstrap-sass!
+ bootstrap-sass
bootstrap_kaminari!
brice
cancan
@@ -335,7 +320,7 @@ DEPENDENCIES
foreman
haml-rails
jquery-rails
- kaminari!
+ kaminari
looksee
mini_magick
mysql2
@@ -350,7 +335,7 @@ DEPENDENCIES
ruby-debug19
sass-rails (~> 3.2.3)
settingslogic
- simple_form!
+ simple_form
syntax
taps
thin
View
22 app/assets/javascripts/jquery.validate.bootstrap.js
@@ -1,19 +1,19 @@
(function() {
$.validator.setDefaults({
- errorClass: "error",
- validClass: "success",
- errorElement: "span",
+ errorClass: 'error',
+ validClass: 'success',
+ errorElement: 'span',
highlight: function(element, errorClass, validClass) {
var $obj;
$obj = element.type === 'radio' ? this.findByName(element.name) : $(element);
- return $obj.parents("div.control-group").removeClass(validClass).addClass(errorClass);
+ return $obj.parents('div.control-group').removeClass(validClass).addClass(errorClass);
},
unhighlight: function(element, errorClass, validClass) {
var $obj;
$obj = element.type === 'radio' ? this.findByName(element.name) : $(element);
$obj.next('span.help-inline.' + errorClass).remove();
- return $obj.parents("div.control-group").removeClass(errorClass).addClass(validClass);
+ return $obj.parents('div.control-group').removeClass(errorClass).addClass(validClass);
},
errorPlacement: function(error, element) {
if (element.siblings().length > 0) {
@@ -50,14 +50,20 @@
return $(this.settings.errorElement + '.' + errorClass, this.errorContext);
};
+ $.validator.prototype.optional = function(element) {
+ return $(element).hasClass('optional') || (!$.validator.methods.required.call(this, $.trim(element.value), element) && 'dependency-mismatch');
+ };
+
$.validator.prototype.showLabel = function(element, message) {
var label;
label = this.errorsFor(element);
if (label.length === 0) {
var railsGenerated = $(element).next('span.help-inline');
if (railsGenerated.length) {
- railsGenerated.attr('for', this.idOrName(element))
- railsGenerated.attr('generated', 'true');
+ railsGenerated.attr({
+ 'for': this.idOrName(element),
+ 'generated': 'true'
+ });
label = railsGenerated;
}
}
@@ -67,7 +73,7 @@
} else {
label = $('<' + this.settings.errorElement + '/>').attr({
'for': this.idOrName(element),
- generated: true
+ 'generated': true
}).addClass(this.settings.errorClass).html(message || '').addClass('help-inline');
if (this.settings.wrapper) {
label = label.hide().show().wrap('<' + this.settings.wrapper + '/>').parent();
View
3  app/assets/javascripts/photo_sets.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
3  app/assets/javascripts/photos.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
11 app/assets/stylesheets/_welcome.css.scss → app/assets/stylesheets/_pages.css.scss
@@ -1,4 +1,4 @@
-.welcome {
+.pages {
#bg {
position: fixed;
top: 0px;
@@ -37,11 +37,20 @@
color: #ccc;
text-shadow: 1px 2px 0 rgba(0,0,0,.7);
font-weight: 300;
+ margin-bottom: 24px;
}
p {
color: #ccc;
text-shadow: 1px 1px 0 rgba(0,0,0,.7);
+
+ &:last-child {
+ margin-bottom: 0;
+ }
+
+ a {
+ font-weight: bold;
+ }
}
strong {
View
2  app/assets/stylesheets/layout.css.scss
@@ -3,4 +3,4 @@
@import 'bootstrap-responsive';
@import 'shared';
@import 'registrations';
-@import 'welcome';
+@import 'pages';
View
3  app/assets/stylesheets/photo_sets.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the PhotoSets controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
3  app/assets/stylesheets/photos.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the Photos controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
7 app/controllers/admin_controller.rb
@@ -0,0 +1,7 @@
+class AdminController < ApplicationController
+ before_filter :authenticate_user!
+ before_filter :admin_only
+
+ def index
+ end
+end
View
4 app/controllers/application_controller.rb
@@ -1,3 +1,7 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+
+ def admin_only
+ redirect_to(root_path, :notice => "You're not allowed here!") unless current_user.admin?
+ end
end
View
7 app/controllers/pages_controller.rb
@@ -0,0 +1,7 @@
+class PagesController < ApplicationController
+ def welcome
+ end
+
+ def contact
+ end
+end
View
83 app/controllers/photo_sets_controller.rb
@@ -0,0 +1,83 @@
+class PhotoSetsController < ApplicationController
+ # GET /photo_sets
+ # GET /photo_sets.json
+ def index
+ @photo_sets = PhotoSet.all
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.json { render json: @photo_sets }
+ end
+ end
+
+ # GET /photo_sets/1
+ # GET /photo_sets/1.json
+ def show
+ @photo_set = PhotoSet.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @photo_set }
+ end
+ end
+
+ # GET /photo_sets/new
+ # GET /photo_sets/new.json
+ def new
+ @photo_set = PhotoSet.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @photo_set }
+ end
+ end
+
+ # GET /photo_sets/1/edit
+ def edit
+ @photo_set = PhotoSet.find(params[:id])
+ end
+
+ # POST /photo_sets
+ # POST /photo_sets.json
+ def create
+ @photo_set = PhotoSet.new(params[:photo_set])
+
+ respond_to do |format|
+ if @photo_set.save
+ format.html { redirect_to @photo_set, notice: 'Photo set was successfully created.' }
+ format.json { render json: @photo_set, status: :created, location: @photo_set }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @photo_set.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /photo_sets/1
+ # PUT /photo_sets/1.json
+ def update
+ @photo_set = PhotoSet.find(params[:id])
+
+ respond_to do |format|
+ if @photo_set.update_attributes(params[:photo_set])
+ format.html { redirect_to @photo_set, notice: 'Photo set was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @photo_set.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /photo_sets/1
+ # DELETE /photo_sets/1.json
+ def destroy
+ @photo_set = PhotoSet.find(params[:id])
+ @photo_set.destroy
+
+ respond_to do |format|
+ format.html { redirect_to photo_sets_url }
+ format.json { head :no_content }
+ end
+ end
+end
View
86 app/controllers/photos_controller.rb
@@ -0,0 +1,86 @@
+class PhotosController < ApplicationController
+ # NOTE: Nested in PhotoSet resource
+
+ # GET /photo_set/1/photos
+ # GET /photo_set/1/photos.json
+ def index
+ @photo_set = PhotoSet.find(params[:photo_set_id])
+ redirect_to @photo_set
+ end
+
+ # GET /photo_set/1/photos/1
+ # GET /photo_set/1/photos/1.json
+ def show
+ @photo_set = PhotoSet.find(params[:photo_set_id])
+ @photo = Photo.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.json { render json: @photo }
+ end
+ end
+
+ # GET /photo_set/1/photos/new
+ # GET /photo_set/1/photos/new.json
+ def new
+ @photo_set = PhotoSet.find(params[:photo_set_id])
+ @photo = Photo.new(:photo_set_id => @photo_set.id)
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.json { render json: @photo }
+ end
+ end
+
+ # GET /photo_set/1/photos/1/edit
+ def edit
+ @photo_set = PhotoSet.find(params[:photo_set_id])
+ @photo = Photo.find(params[:id])
+ end
+
+ # POST /photo_set/1/photos
+ # POST /photo_set/1/photos.json
+ def create
+ @photo_set = PhotoSet.find(params[:photo_set_id])
+ @photo = Photo.new(params[:photo].merge(:photo_set_id => @photo_set.id))
+
+ respond_to do |format|
+ if @photo.save
+ format.html { redirect_to [@photo_set, @photo], notice: 'Photo was successfully created.' }
+ format.json { render json: [@photo_set, @photo], status: :created, location: [@photo_set, @photo] }
+ else
+ format.html { render action: "new" }
+ format.json { render json: @photo.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # PUT /photo_set/1/photos/1
+ # PUT /photo_set/1/photos/1.json
+ def update
+ @photo = Photo.find(params[:id])
+
+ respond_to do |format|
+ if @photo.update_attributes(params[:photo])
+ format.html { redirect_to [@photo_set, @photo], notice: 'Photo was successfully updated.' }
+ format.json { head :no_content }
+ else
+ format.html { render action: "edit" }
+ format.json { render json: @photo.errors, status: :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /photo_set/1/photos/1
+ # DELETE /photo_set/1/photos/1.json
+ def destroy
+ @photo_set = PhotoSet.find(params[:photo_set_id])
+ @photo = Photo.find(params[:id])
+ @photo.destroy
+
+ respond_to do |format|
+ format.html { redirect_to photo_set_photos_url(@photo_set) }
+ format.json { head :no_content }
+ end
+ end
+end
View
9 app/controllers/welcome_controller.rb
@@ -1,9 +0,0 @@
-class WelcomeController < ApplicationController
- skip_before_filter :authenticate_user!, :only => :index
-
- def index
- redirect_to dashboard_path if user_signed_in?
-
- @user = User.new
- end
-end
View
2  app/helpers/photo_sets_helper.rb
@@ -0,0 +1,2 @@
+module PhotoSetsHelper
+end
View
2  app/helpers/photos_helper.rb
@@ -0,0 +1,2 @@
+module PhotosHelper
+end
View
15 app/models/ability.rb
@@ -3,14 +3,13 @@ class Ability
def initialize(user)
# Define abilities for the passed in user here. For example:
- #
- # user ||= User.new # guest user (not logged in)
- # if user.admin?
- # can :manage, :all
- # else
- # can :read, :all
- # end
- #
+
+ user ||= User.new # guest user (not logged in)
+
+ if user.admin?
+ can :manage, :all
+ end
+
# The first argument to `can` is the action you are giving the user permission to do.
# If you pass :manage it will apply to every action. Other common actions here are
# :read, :create, :update and :destroy.
View
10 app/models/photo.rb
@@ -0,0 +1,10 @@
+class Photo < ActiveRecord::Base
+ belongs_to :photo_set
+
+ validates :name, :presence => true
+ validates :description, :presence => true
+ validates :photo_set, :presence => true
+ validates :image, :presence => true
+
+ mount_uploader :image, PhotoUploader
+end
View
6 app/models/photo_set.rb
@@ -0,0 +1,6 @@
+class PhotoSet < ActiveRecord::Base
+ has_many :photos
+
+ validates :name, :presence => true
+ validates :description, :presence => true
+end
View
6 app/models/user.rb
@@ -5,8 +5,12 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
- attr_accessible :email, :password, :password_confirmation, :remember_me, :admin, :avatar, :avatar_cache, :remove_avatar, :remote_avatar_url
+ attr_accessible :email, :password, :password_confirmation, :remember_me, :role, :avatar, :avatar_cache, :remove_avatar, :remote_avatar_url
serialize :data
mount_uploader :avatar, AvatarUploader
+
+ def admin?
+ role == 'admin'
+ end
end
View
2  app/uploaders/avatar_uploader.rb
@@ -1,6 +1,4 @@
class AvatarUploader < CarrierWave::Uploader::Base
- # Include RMagick or MiniMagick support:
- # include CarrierWave::RMagick
include CarrierWave::MiniMagick
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
View
49 app/uploaders/photo_uploader.rb
@@ -0,0 +1,49 @@
+class PhotoUploader < CarrierWave::Uploader::Base
+ include CarrierWave::MiniMagick
+ include Sprockets::Helpers::RailsHelper
+ include Sprockets::Helpers::IsolatedHelper
+
+ # Choose what kind of storage to use for this uploader:
+ if Rails.env.test?
+ storage :file
+ else
+ storage :fog
+ end
+
+ # Override the directory where uploaded files will be stored.
+ # This is a sensible default for uploaders that are meant to be mounted:
+ def store_dir
+ "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
+ end
+
+ # Provide a default URL as a default if there hasn't been a file uploaded:
+ def default_url
+ asset_path('default.png')
+ end
+
+ # Process files as they are uploaded:
+ # process :scale => [200, 300]
+ #
+ # def scale(width, height)
+ # # do something
+ # end
+
+ process :resize_to_fill => [800, 800]
+
+ # Create different versions of your uploaded files:
+ version :thumbnail do
+ process :resize_to_fill => [100, 100]
+ end
+
+ # Add a white list of extensions which are allowed to be uploaded.
+ # For images you might use something like this:
+ # def extension_white_list
+ # %w(jpg jpeg gif png)
+ # end
+
+ # Override the filename of the uploaded files:
+ # Avoid using model.id or version_name here, see uploader/store.rb for details.
+ # def filename
+ # "something.jpg" if original_filename
+ # end
+end
View
17 app/views/admin/index.html.haml
@@ -0,0 +1,17 @@
+.container
+ .content
+ .row
+ .span12= alert_message_for(flash)
+
+ .page-header
+ %h1 Admin
+
+ .row
+ .span12
+ %h2 Welcome, <strong>#{current_user.email}</strong>.
+
+ %p Here is your user data...
+
+ %pre
+ %code
+ = current_user.to_yaml
View
1  app/views/devise/registrations/new.html.haml
@@ -12,4 +12,3 @@
= f.input :password_confirmation, :required => true
.form-actions
= f.button :submit, 'Sign up', :class => 'btn-primary btn-large'
- = link_to 'Or, sign up using Facebook', omniauth_authorize_path(resource_name, :facebook)
View
1  app/views/devise/sessions/new.html.haml
@@ -14,7 +14,6 @@
= f.input :remember_me, :as => :boolean if devise_mapping.rememberable?
.form-actions
= f.button :submit, 'Sign in', :class => 'btn-primary btn-large'
- = link_to 'Or, sign in using Facebook', omniauth_authorize_path(resource_name, :facebook)
.span4
%h3 Can't remember?
View
5 app/views/pages/contact.html.haml
@@ -0,0 +1,5 @@
+#bg{:style => "background-image: url('#{asset_path('photos/willis.jpg')}');"}
+
+.hero-unit
+ %h1 So, you want to <strong>contact</strong> me?
+ %p You could #{mail_to('sam@samnichollsphotography.com', 'email me')}.
View
0  app/views/welcome/index.html.haml → app/views/pages/welcome.html.haml
File renamed without changes
View
9 app/views/photo_sets/_form.html.haml
@@ -0,0 +1,9 @@
+= simple_form_for(@photo_set) do |f|
+ = f.error_notification
+
+ %fieldset
+ = f.input :name, :required => true
+ = f.input :description, :required => true
+
+ .form-actions
+ = f.button :submit, :class => 'btn-primary btn-large'
View
43 app/views/photo_sets/edit.html.haml
@@ -0,0 +1,43 @@
+.container
+ .content
+ .row
+ .span12= alert_message_for(flash)
+
+ .page-header
+ %h1
+ Photo Set
+ %small Edit
+
+ %h2= @photo_set.name
+
+ .row
+ .span8
+ = render 'form'
+ .span4
+ .well
+ %h3 Photos in this Photo Set
+
+ %table.table.table-bordered.table-striped.table-condensed
+ %thead
+ %tr
+ %th Name
+ %th Description
+ %th Image
+ %th
+ %tbody
+ - @photo_set.photos.each do |photo|
+ %tr
+ %td= photo.name
+ %td= photo.description
+ %td= image_tag(photo.image.thumbnail.url)
+ %td
+ = link_to 'Show', photo_set_photo_path(@photo_set, photo)
+ = link_to 'Edit', edit_photo_set_photo_path(@photo_set, photo)
+ = link_to 'Destroy', photo_set_photo_path(@photo_set, photo), :confirm => 'Are you sure?', :method => :delete
+
+ %p= link_to 'Add a Photo', new_photo_set_photo_path(@photo_set), :class => 'btn btn-mini'
+
+ .row
+ .span12
+ = link_to 'Show', @photo_set, :class => 'btn'
+ = link_to 'Back', photo_sets_path
View
36 app/views/photo_sets/index.html.haml
@@ -0,0 +1,36 @@
+.container
+ .content
+ .row
+ .span12= alert_message_for(flash)
+
+ .page-header
+ %h1
+ Photo Sets
+ %small Collections of Photos
+
+ %h2 Choose a Photo Set
+
+ .row
+ .span12
+ %table.table.table-bordered.table-striped
+ %thead
+ %tr
+ %th Name
+ - if user_signed_in? && current_user.admin?
+ %th
+ %tbody
+ - @photo_sets.each do |photo_set|
+ %tr
+ %td= link_to photo_set.name, photo_set
+ - if user_signed_in? && current_user.admin?
+ %td
+ = link_to 'Show', photo_set
+ = link_to 'Edit', edit_photo_set_path(photo_set)
+ = link_to 'Destroy', photo_set, :confirm => 'Are you sure?', :method => :delete
+
+ .row
+ .span12
+ %p
+ - if user_signed_in? && current_user.admin?
+ = link_to 'New Photo Set', new_photo_set_path, :class => 'btn btn-primary'
+ = link_to 'Back', root_path
View
19 app/views/photo_sets/new.html.haml
@@ -0,0 +1,19 @@
+.container
+ .content
+ .row
+ .span12= alert_message_for(flash)
+
+ .page-header
+ %h1
+ Photo Set
+ %small New
+
+ %h2 Create a new Photo Set
+
+ .row
+ .span12
+ = render 'form'
+
+ .row
+ .span12
+ = link_to 'Back', photo_sets_path
View
31 app/views/photo_sets/show.html.haml
@@ -0,0 +1,31 @@
+.container
+ .content
+ .row
+ .span12= alert_message_for(flash)
+
+ .page-header
+ %h1
+ = @photo_set.name
+ %small Photo Set
+
+ %h2= @photo_set.description
+
+ .row
+ .span12
+ - if @photo_set.photos.blank?
+ There are no Photos for this Photo Set yet.
+ - else
+ %ul.thumbnails
+ - @photo_set.photos.each do |photo|
+ %li
+ .thumbnail
+ = link_to image_tag(photo.image.thumbnail.url, :alt => photo.name), [@photo_set, photo]
+ .caption
+ %h5= link_to photo.name, [@photo_set, photo]
+ %p= photo.description
+
+ .span12
+ %p
+ - if user_signed_in? && current_user.admin?
+ = link_to 'Edit', edit_photo_set_path(@photo_set), :class => 'btn btn-primary'
+ = link_to 'Back', photo_sets_path
View
10 app/views/photos/_form.html.haml
@@ -0,0 +1,10 @@
+= simple_form_for([@photo_set, @photo]) do |f|
+ = f.error_notification
+
+ %fieldset
+ = f.input :name, :required => true
+ = f.input :description, :required => true
+ = f.input :image, :required => true, :as => :image_preview, :input_html => { :preview_version => :tiny }
+
+ .form-actions
+ = f.button :submit, :class => 'btn-primary btn-large'
View
20 app/views/photos/edit.html.haml
@@ -0,0 +1,20 @@
+.container
+ .content
+ .row
+ .span12= alert_message_for(flash)
+
+ .page-header
+ %h1
+ Photo
+ %small Edit
+
+ %h2= @photo.name
+
+ .row
+ .span12
+ = render 'form'
+
+ .row
+ .span12
+ = link_to 'Show', photo_set_photo_path(@photo_set, @photo), :class => 'btn'
+ = link_to 'Back', photo_sets_photos_path(@photo_set)
View
19 app/views/photos/new.html.haml
@@ -0,0 +1,19 @@
+.container
+ .content
+ .row
+ .span12= alert_message_for(flash)
+
+ .page-header
+ %h1
+ Photo
+ %small= @photo_set.name
+
+ %h2 Create a new Photo
+
+ .row
+ .span12
+ = render 'form'
+
+ .row
+ .span12
+ = link_to 'Back', photo_set_photos_path(@photo_set)
View
21 app/views/photos/show.html.haml
@@ -0,0 +1,21 @@
+.container
+ .content
+ .row
+ .span12= alert_message_for(flash)
+
+ .page-header
+ %h1
+ = @photo.name
+ %small= @photo_set.name
+
+ %h2= @photo.description
+
+ .row
+ .span12
+ = image_tag(@photo.image.url, :alt => @photo.name, :class => 'thumbnail')
+ .row
+ .span12
+ %p
+ - if user_signed_in? && current_user.admin?
+ = link_to 'Edit', edit_photo_set_photo_path(@photo_set, @photo), :class => 'btn btn-primary'
+ = link_to 'Back', photo_set_photos_path(@photo_set)
View
15 app/views/shared/_navbar.html.haml
@@ -9,3 +9,18 @@
%span.icon-bar
.nav-collapse
+ - if user_signed_in? && current_user.admin?
+ %ul.nav.user-actions.pull-right
+ %li.divider-vertical
+ %li.dropdown
+ = link_to '#', :class => 'dropdown-toggle logged-in-user-toggle', :'data-toggle' => 'dropdown' do
+ = image_tag current_user.avatar.tiny.url, :alt => current_user.email, :size => '20x20', :class => 'avatar'
+ = current_user.email
+ %b.caret
+ %ul.dropdown-menu
+ %li= link_to 'Settings', edit_user_registration_path
+ %li.divider
+ %li= link_to 'Log out', destroy_user_session_path, :method => :delete
+ %ul.nav.pull-right
+ %li= link_to 'The Gallery', photo_sets_path, :class => controller_name.match(/photo/) ? 'active' : nil
+ %li= link_to 'Contact', contact_path, :class => action_name.match(/contact/) ? 'active' : nil
View
2  config/application.yml
@@ -2,7 +2,7 @@ defaults: &defaults
aws:
access_key_id: <%= ENV['AWS_ACCESS_KEY_ID'] %>
secret_access_key: <%= ENV['AWS_SECRET_ACCESS_KEY'] %>
- bucket_name: gallery
+ bucket_name: sn-gallery
development:
<<: *defaults
View
12 config/routes.rb
@@ -1,10 +1,18 @@
Gallery::Application.routes.draw do
- mount Resque::Server.new, :at => '/resque'
+ match 'admin' => 'admin#index'
- root :to => 'welcome#index'
+ resources :photo_sets do
+ resources :photos
+ end
devise_for :users
+ mount Resque::Server.new, :at => '/resque'
+
+ match 'contact' => 'pages#contact'
+
+ root :to => 'pages#welcome'
+
# The priority is based upon order of creation:
# first created -> highest priority.
View
10 db/migrate/20120416161734_create_photo_sets.rb
@@ -0,0 +1,10 @@
+class CreatePhotoSets < ActiveRecord::Migration
+ def change
+ create_table :photo_sets do |t|
+ t.string :name
+ t.string :description
+
+ t.timestamps
+ end
+ end
+end
View
12 db/migrate/20120416161925_create_photos.rb
@@ -0,0 +1,12 @@
+class CreatePhotos < ActiveRecord::Migration
+ def change
+ create_table :photos do |t|
+ t.string :name
+ t.string :description
+ t.string :image
+ t.belongs_to :photo_set
+
+ t.timestamps
+ end
+ end
+end
View
18 db/schema.rb
@@ -11,7 +11,23 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120222225435) do
+ActiveRecord::Schema.define(:version => 20120416161925) do
+
+ create_table "photo_sets", :force => true do |t|
+ t.string "name"
+ t.string "description"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ create_table "photos", :force => true do |t|
+ t.string "name"
+ t.string "description"
+ t.string "image"
+ t.integer "photo_set_id"
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
create_table "users", :force => true do |t|
t.string "email", :default => "", :null => false
View
3  db/seeds.rb
@@ -5,3 +5,6 @@
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
+
+User.create(:email => 'me@tonycoconate.com', :password => 'cocomen3', :role => 'admin')
+User.create(:email => 'namsicklz@googlemail.com', :password => 'abc123', :role => 'admin')
View
164 spec/controllers/photo_sets_controller_spec.rb
@@ -0,0 +1,164 @@
+require 'spec_helper'
+
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by Rails when you ran the scaffold generator.
+#
+# It assumes that the implementation code is generated by the rails scaffold
+# generator. If you are using any extension libraries to generate different
+# controller code, this generated spec may or may not pass.
+#
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
+#
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
+
+describe PhotoSetsController do
+
+ # This should return the minimal set of attributes required to create a valid
+ # PhotoSet. As you add validations to PhotoSet, be sure to
+ # update the return value of this method accordingly.
+ def valid_attributes
+ {}
+ end
+
+ # This should return the minimal set of values that should be in the session
+ # in order to pass any filters (e.g. authentication) defined in
+ # PhotoSetsController. Be sure to keep this updated too.
+ def valid_session
+ {}
+ end
+
+ describe "GET index" do
+ it "assigns all photo_sets as @photo_sets" do
+ photo_set = PhotoSet.create! valid_attributes
+ get :index, {}, valid_session
+ assigns(:photo_sets).should eq([photo_set])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested photo_set as @photo_set" do
+ photo_set = PhotoSet.create! valid_attributes
+ get :show, {:id => photo_set.to_param}, valid_session
+ assigns(:photo_set).should eq(photo_set)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new photo_set as @photo_set" do
+ get :new, {}, valid_session
+ assigns(:photo_set).should be_a_new(PhotoSet)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested photo_set as @photo_set" do
+ photo_set = PhotoSet.create! valid_attributes
+ get :edit, {:id => photo_set.to_param}, valid_session
+ assigns(:photo_set).should eq(photo_set)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new PhotoSet" do
+ expect {
+ post :create, {:photo_set => valid_attributes}, valid_session
+ }.to change(PhotoSet, :count).by(1)
+ end
+
+ it "assigns a newly created photo_set as @photo_set" do
+ post :create, {:photo_set => valid_attributes}, valid_session
+ assigns(:photo_set).should be_a(PhotoSet)
+ assigns(:photo_set).should be_persisted
+ end
+
+ it "redirects to the created photo_set" do
+ post :create, {:photo_set => valid_attributes}, valid_session
+ response.should redirect_to(PhotoSet.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved photo_set as @photo_set" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ PhotoSet.any_instance.stub(:save).and_return(false)
+ post :create, {:photo_set => {}}, valid_session
+ assigns(:photo_set).should be_a_new(PhotoSet)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ PhotoSet.any_instance.stub(:save).and_return(false)
+ post :create, {:photo_set => {}}, valid_session
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested photo_set" do
+ photo_set = PhotoSet.create! valid_attributes
+ # Assuming there are no other photo_sets in the database, this
+ # specifies that the PhotoSet created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ PhotoSet.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, {:id => photo_set.to_param, :photo_set => {'these' => 'params'}}, valid_session
+ end
+
+ it "assigns the requested photo_set as @photo_set" do
+ photo_set = PhotoSet.create! valid_attributes
+ put :update, {:id => photo_set.to_param, :photo_set => valid_attributes}, valid_session
+ assigns(:photo_set).should eq(photo_set)
+ end
+
+ it "redirects to the photo_set" do
+ photo_set = PhotoSet.create! valid_attributes
+ put :update, {:id => photo_set.to_param, :photo_set => valid_attributes}, valid_session
+ response.should redirect_to(photo_set)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the photo_set as @photo_set" do
+ photo_set = PhotoSet.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ PhotoSet.any_instance.stub(:save).and_return(false)
+ put :update, {:id => photo_set.to_param, :photo_set => {}}, valid_session
+ assigns(:photo_set).should eq(photo_set)
+ end
+
+ it "re-renders the 'edit' template" do
+ photo_set = PhotoSet.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ PhotoSet.any_instance.stub(:save).and_return(false)
+ put :update, {:id => photo_set.to_param, :photo_set => {}}, valid_session
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested photo_set" do
+ photo_set = PhotoSet.create! valid_attributes
+ expect {
+ delete :destroy, {:id => photo_set.to_param}, valid_session
+ }.to change(PhotoSet, :count).by(-1)
+ end
+
+ it "redirects to the photo_sets list" do
+ photo_set = PhotoSet.create! valid_attributes
+ delete :destroy, {:id => photo_set.to_param}, valid_session
+ response.should redirect_to(photo_sets_url)
+ end
+ end
+
+end
View
164 spec/controllers/photos_controller_spec.rb
@@ -0,0 +1,164 @@
+require 'spec_helper'
+
+# This spec was generated by rspec-rails when you ran the scaffold generator.
+# It demonstrates how one might use RSpec to specify the controller code that
+# was generated by Rails when you ran the scaffold generator.
+#
+# It assumes that the implementation code is generated by the rails scaffold
+# generator. If you are using any extension libraries to generate different
+# controller code, this generated spec may or may not pass.
+#
+# It only uses APIs available in rails and/or rspec-rails. There are a number
+# of tools you can use to make these specs even more expressive, but we're
+# sticking to rails and rspec-rails APIs to keep things simple and stable.
+#
+# Compared to earlier versions of this generator, there is very limited use of
+# stubs and message expectations in this spec. Stubs are only used when there
+# is no simpler way to get a handle on the object needed for the example.
+# Message expectations are only used when there is no simpler way to specify
+# that an instance is receiving a specific message.
+
+describe PhotosController do
+
+ # This should return the minimal set of attributes required to create a valid
+ # Photo. As you add validations to Photo, be sure to
+ # update the return value of this method accordingly.
+ def valid_attributes
+ {}
+ end
+
+ # This should return the minimal set of values that should be in the session
+ # in order to pass any filters (e.g. authentication) defined in
+ # PhotosController. Be sure to keep this updated too.
+ def valid_session
+ {}
+ end
+
+ describe "GET index" do
+ it "assigns all photos as @photos" do
+ photo = Photo.create! valid_attributes
+ get :index, {}, valid_session
+ assigns(:photos).should eq([photo])
+ end
+ end
+
+ describe "GET show" do
+ it "assigns the requested photo as @photo" do
+ photo = Photo.create! valid_attributes
+ get :show, {:id => photo.to_param}, valid_session
+ assigns(:photo).should eq(photo)
+ end
+ end
+
+ describe "GET new" do
+ it "assigns a new photo as @photo" do
+ get :new, {}, valid_session
+ assigns(:photo).should be_a_new(Photo)
+ end
+ end
+
+ describe "GET edit" do
+ it "assigns the requested photo as @photo" do
+ photo = Photo.create! valid_attributes
+ get :edit, {:id => photo.to_param}, valid_session
+ assigns(:photo).should eq(photo)
+ end
+ end
+
+ describe "POST create" do
+ describe "with valid params" do
+ it "creates a new Photo" do
+ expect {
+ post :create, {:photo => valid_attributes}, valid_session
+ }.to change(Photo, :count).by(1)
+ end
+
+ it "assigns a newly created photo as @photo" do
+ post :create, {:photo => valid_attributes}, valid_session
+ assigns(:photo).should be_a(Photo)
+ assigns(:photo).should be_persisted
+ end
+
+ it "redirects to the created photo" do
+ post :create, {:photo => valid_attributes}, valid_session
+ response.should redirect_to(Photo.last)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns a newly created but unsaved photo as @photo" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Photo.any_instance.stub(:save).and_return(false)
+ post :create, {:photo => {}}, valid_session
+ assigns(:photo).should be_a_new(Photo)
+ end
+
+ it "re-renders the 'new' template" do
+ # Trigger the behavior that occurs when invalid params are submitted
+ Photo.any_instance.stub(:save).and_return(false)
+ post :create, {:photo => {}}, valid_session
+ response.should render_template("new")
+ end
+ end
+ end
+
+ describe "PUT update" do
+ describe "with valid params" do
+ it "updates the requested photo" do
+ photo = Photo.create! valid_attributes
+ # Assuming there are no other photos in the database, this
+ # specifies that the Photo created on the previous line
+ # receives the :update_attributes message with whatever params are
+ # submitted in the request.
+ Photo.any_instance.should_receive(:update_attributes).with({'these' => 'params'})
+ put :update, {:id => photo.to_param, :photo => {'these' => 'params'}}, valid_session
+ end
+
+ it "assigns the requested photo as @photo" do
+ photo = Photo.create! valid_attributes
+ put :update, {:id => photo.to_param, :photo => valid_attributes}, valid_session
+ assigns(:photo).should eq(photo)
+ end
+
+ it "redirects to the photo" do
+ photo = Photo.create! valid_attributes
+ put :update, {:id => photo.to_param, :photo => valid_attributes}, valid_session
+ response.should redirect_to(photo)
+ end
+ end
+
+ describe "with invalid params" do
+ it "assigns the photo as @photo" do
+ photo = Photo.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ Photo.any_instance.stub(:save).and_return(false)
+ put :update, {:id => photo.to_param, :photo => {}}, valid_session
+ assigns(:photo).should eq(photo)
+ end
+
+ it "re-renders the 'edit' template" do
+ photo = Photo.create! valid_attributes
+ # Trigger the behavior that occurs when invalid params are submitted
+ Photo.any_instance.stub(:save).and_return(false)
+ put :update, {:id => photo.to_param, :photo => {}}, valid_session
+ response.should render_template("edit")
+ end
+ end
+ end
+
+ describe "DELETE destroy" do
+ it "destroys the requested photo" do
+ photo = Photo.create! valid_attributes
+ expect {
+ delete :destroy, {:id => photo.to_param}, valid_session
+ }.to change(Photo, :count).by(-1)
+ end
+
+ it "redirects to the photos list" do
+ photo = Photo.create! valid_attributes
+ delete :destroy, {:id => photo.to_param}, valid_session
+ response.should redirect_to(photos_url)
+ end
+ end
+
+end
View
8 spec/factories/photo_sets.rb
@@ -0,0 +1,8 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :photo_set do
+ name "MyString"
+ description "MyString"
+ end
+end
View
9 spec/factories/photos.rb
@@ -0,0 +1,9 @@
+# Read about factories at https://github.com/thoughtbot/factory_girl
+
+FactoryGirl.define do
+ factory :photo do
+ name "MyString"
+ description "MyString"
+ image "MyString"
+ end
+end
View
5 spec/models/photo_set_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe PhotoSet do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
5 spec/models/photo_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe Photo do
+ pending "add some examples to (or delete) #{__FILE__}"
+end
View
11 spec/requests/photo_sets_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "PhotoSets" do
+ describe "GET /photo_sets" do
+ it "works! (now write some real specs)" do
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
+ get photo_sets_path
+ response.status.should be(200)
+ end
+ end
+end
View
11 spec/requests/photos_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe "Photos" do
+ describe "GET /photos" do
+ it "works! (now write some real specs)" do
+ # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
+ get photos_path
+ response.status.should be(200)
+ end
+ end
+end
View
35 spec/routing/photo_sets_routing_spec.rb
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe PhotoSetsController do
+ describe "routing" do
+
+ it "routes to #index" do
+ get("/photo_sets").should route_to("photo_sets#index")
+ end
+
+ it "routes to #new" do
+ get("/photo_sets/new").should route_to("photo_sets#new")
+ end
+
+ it "routes to #show" do
+ get("/photo_sets/1").should route_to("photo_sets#show", :id => "1")
+ end
+
+ it "routes to #edit" do
+ get("/photo_sets/1/edit").should route_to("photo_sets#edit", :id => "1")
+ end
+
+ it "routes to #create" do
+ post("/photo_sets").should route_to("photo_sets#create")
+ end
+
+ it "routes to #update" do
+ put("/photo_sets/1").should route_to("photo_sets#update", :id => "1")
+ end
+
+ it "routes to #destroy" do
+ delete("/photo_sets/1").should route_to("photo_sets#destroy", :id => "1")
+ end
+
+ end
+end
View
35 spec/routing/photos_routing_spec.rb
@@ -0,0 +1,35 @@
+require "spec_helper"
+
+describe PhotosController do
+ describe "routing" do
+
+ it "routes to #index" do
+ get("/photos").should route_to("photos#index")
+ end
+
+ it "routes to #new" do
+ get("/photos/new").should route_to("photos#new")
+ end
+
+ it "routes to #show" do
+ get("/photos/1").should route_to("photos#show", :id => "1")
+ end
+
+ it "routes to #edit" do
+ get("/photos/1/edit").should route_to("photos#edit", :id => "1")
+ end
+
+ it "routes to #create" do
+ post("/photos").should route_to("photos#create")
+ end
+
+ it "routes to #update" do
+ put("/photos/1").should route_to("photos#update", :id => "1")
+ end
+
+ it "routes to #destroy" do
+ delete("/photos/1").should route_to("photos#destroy", :id => "1")
+ end
+
+ end
+end

No commit comments for this range

Something went wrong with that request. Please try again.