Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

A separate charts controller

  • Loading branch information...
commit 83d84fb5862f9e0045c58e37061ed14b81f3615c 1 parent 33dadde
@iain authored
View
1  .rspec
@@ -1 +1,2 @@
--colour
+--order rand
View
8 app/controllers/charts_controller.rb
@@ -0,0 +1,8 @@
+class ChartsController < ApplicationController
+
+ def show
+ project = Project.find(params[:project_id])
+ render :json => Charts::Overview[project]
+ end
+
+end
View
2  app/controllers/iframes_controller.rb
@@ -2,4 +2,6 @@ class IframesController < InheritedResources::Base
belongs_to :project
+ actions :all, :except => :index
+
end
View
47 app/controllers/projects_controller.rb
@@ -1,47 +1,2 @@
-class ProjectsController < ApplicationController
-
- def index
- end
-
- def new
- @project = Project.new
- end
-
- def show
- @project = Project.find(params[:id])
- respond_to do |format|
- format.html
- format.json { render :json => Charts::Overview[@project] }
- end
- end
-
- def create
- @project = Project.new(params[:project])
- if @project.save
- redirect_to @project, :notice => "Project was created"
- else
- render :new
- end
- end
-
- def edit
- @project = Project.find(params[:id])
- end
-
- def update
- @project = Project.find(params[:id])
- if @project.update_attributes(params[:project])
- redirect_to :back, :notice => "Project updated"
- else
- flash.now[:alert] = "Project could not be updated"
- render :edit
- end
- end
-
- def destroy
- @project = Project.find(params[:id])
- @project.destroy
- redirect_to root_url
- end
-
+class ProjectsController < InheritedResources::Base
end
View
4 app/models/iframe.rb
@@ -4,10 +4,10 @@ class Iframe < ActiveRecord::Base
friendly_id :name, :use => :slugged
validates_presence_of :name
- validates_uniqueness_of :name, :scope => :project_id
+ validates_uniqueness_of :name, :scope => :project_id, :case_sensitive => false
validates_presence_of :url
- validates_uniqueness_of :url
+ validates_uniqueness_of :url, :case_sensitive => false
validates_presence_of :project_id
View
2  app/models/project.rb
@@ -4,7 +4,7 @@ class Project < ActiveRecord::Base
friendly_id :name, :use => :slugged
validates_presence_of :name
- validates_uniqueness_of :name
+ validates_uniqueness_of :name, :case_sensitive => false
has_many :iframes
View
3  app/views/iframes/edit.html.haml
@@ -3,3 +3,6 @@
%h2 Edit iFrame
= render "form"
+
+.well
+ = link_to "Delete iFrame", project_iframe_path(@project, @iframe), :method => :delete, :class => "btn danger", :confirm => "Damn, girl! Are you sure?"
View
2  app/views/projects/show.html.haml
@@ -1,3 +1,3 @@
= render "header", :project => @project, :tab => "overview"
-#foobar{:data => { :chart => project_path(@project, :format => :json) }}
+#foobar{data(:chart, project_chart_path(@project, :overview))}
View
1  config/routes.rb
@@ -5,6 +5,7 @@
resources :projects do
resources :iframes
+ get "/chart/:id" => "charts#show", :as => :chart
end
View
5 spec/controllers/charts_controller_spec.rb
@@ -0,0 +1,5 @@
+require 'spec_helper'
+
+describe ChartsController do
+
+end
View
1  spec/factories/iframes.rb
@@ -5,5 +5,6 @@
name "MyString"
slug "MyString"
url "MyString"
+ project_id 1
end
end
View
23 spec/models/iframe_spec.rb
@@ -1,5 +1,26 @@
require 'spec_helper'
describe Iframe do
- pending "add some examples to (or delete) #{__FILE__}"
+
+ it { should belong_to(:project) }
+
+ it { should validate_presence_of(:name) }
+ it { should validate_presence_of(:url) }
+ it { should validate_presence_of(:project_id) }
+
+ specify do
+ create :iframe
+ should validate_uniqueness_of(:name).scoped_to(:project_id).case_insensitive
+ end
+
+ specify do
+ create :iframe
+ should validate_uniqueness_of(:url).case_insensitive
+ end
+
+ it "finds by slug" do
+ iframe = create :iframe, :name => "Pretty title"
+ Iframe.find("pretty-title").should == iframe
+ end
+
end
View
9 spec/models/project_spec.rb
@@ -2,10 +2,17 @@
describe Project do
+ it { should have_many(:iframes) }
+
it { should validate_presence_of(:name) }
+ specify do
+ create :project
+ should validate_uniqueness_of(:name).case_insensitive
+ end
+
it "finds by slug" do
- project = Factory :project, :name => "Pretty title"
+ project = create :project, :name => "Pretty title"
Project.find("pretty-title").should == project
end
View
3  spec/spec_helper.rb
@@ -29,4 +29,7 @@
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
+
+ config.include FactoryGirl::Syntax::Methods
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.