Commit 13cbdd9c02f6a18025f69578fd1e767b9c9c47ed
Committed by
Rafael Manzo
1 parent
b925ec18
Exists in
colab
and in
4 other branches
repository scaffold, alter routes for nested resources
Showing
39 changed files
with
994 additions
and
3 deletions
Show diff stats
... | ... | @@ -0,0 +1,69 @@ |
1 | +body { | |
2 | + background-color: #fff; | |
3 | + color: #333; | |
4 | + font-family: verdana, arial, helvetica, sans-serif; | |
5 | + font-size: 13px; | |
6 | + line-height: 18px; | |
7 | +} | |
8 | + | |
9 | +p, ol, ul, td { | |
10 | + font-family: verdana, arial, helvetica, sans-serif; | |
11 | + font-size: 13px; | |
12 | + line-height: 18px; | |
13 | +} | |
14 | + | |
15 | +pre { | |
16 | + background-color: #eee; | |
17 | + padding: 10px; | |
18 | + font-size: 11px; | |
19 | +} | |
20 | + | |
21 | +a { | |
22 | + color: #000; | |
23 | + &:visited { | |
24 | + color: #666; | |
25 | + } | |
26 | + &:hover { | |
27 | + color: #fff; | |
28 | + background-color: #000; | |
29 | + } | |
30 | +} | |
31 | + | |
32 | +div { | |
33 | + &.field, &.actions { | |
34 | + margin-bottom: 10px; | |
35 | + } | |
36 | +} | |
37 | + | |
38 | +#notice { | |
39 | + color: green; | |
40 | +} | |
41 | + | |
42 | +.field_with_errors { | |
43 | + padding: 2px; | |
44 | + background-color: red; | |
45 | + display: table; | |
46 | +} | |
47 | + | |
48 | +#error_explanation { | |
49 | + width: 450px; | |
50 | + border: 2px solid red; | |
51 | + padding: 7px; | |
52 | + padding-bottom: 0; | |
53 | + margin-bottom: 20px; | |
54 | + background-color: #f0f0f0; | |
55 | + h2 { | |
56 | + text-align: left; | |
57 | + font-weight: bold; | |
58 | + padding: 5px 5px 5px 15px; | |
59 | + font-size: 12px; | |
60 | + margin: -7px; | |
61 | + margin-bottom: 0px; | |
62 | + background-color: #c00; | |
63 | + color: #fff; | |
64 | + } | |
65 | + ul li { | |
66 | + font-size: 12px; | |
67 | + list-style: square; | |
68 | + } | |
69 | +} | ... | ... |
app/controllers/projects_controller.rb
... | ... | @@ -0,0 +1,75 @@ |
1 | +class ProjectsController < ApplicationController | |
2 | + | |
3 | + # GET /projects/new | |
4 | + def new | |
5 | + @project = Project.new | |
6 | + end | |
7 | + | |
8 | + # GET /projects | |
9 | + # GET /projects.json | |
10 | + def index | |
11 | + @projects = Project.all | |
12 | + end | |
13 | + | |
14 | + # POST /projects | |
15 | + # POST /projects.json | |
16 | + def create | |
17 | + @project = Project.new(project_params) | |
18 | + | |
19 | + respond_to do |format| | |
20 | + if @project.save | |
21 | + format.html { redirect_to project_path(@project.id), notice: 'Project was successfully created.' } | |
22 | + format.json { render action: 'show', status: :created, location: @project } | |
23 | + else | |
24 | + format.html { render action: 'new' } | |
25 | + format.json { render json: @project.errors, status: :unprocessable_entity } | |
26 | + end | |
27 | + end | |
28 | + end | |
29 | + | |
30 | + # GET /project/1 | |
31 | + # GET /project/1.json | |
32 | + def show | |
33 | + @project_repositories = Repository.repositories_of(params[:id]) | |
34 | + @project_id = (params[:id]) | |
35 | + set_project | |
36 | + end | |
37 | + | |
38 | + # GET /projects/1/edit | |
39 | + # GET /projects/1/edit.json | |
40 | + def edit | |
41 | + set_project | |
42 | + end | |
43 | + | |
44 | + def update | |
45 | + set_project | |
46 | + if @project.update(params[:project]) | |
47 | + redirect_to(project_path(@project.id)) | |
48 | + else | |
49 | + render "edit" | |
50 | + end | |
51 | + end | |
52 | + | |
53 | + # DELETE /project/1 | |
54 | + # DELETE /project/1.json | |
55 | + def destroy | |
56 | + set_project | |
57 | + @project.destroy | |
58 | + respond_to do |format| | |
59 | + format.html { redirect_to projects_url } | |
60 | + format.json { head :no_content } | |
61 | + end | |
62 | + end | |
63 | + | |
64 | + private | |
65 | + # Use callbacks to share common setup or constraints between actions. | |
66 | + def set_project | |
67 | + @project = Project.find(params[:id]) | |
68 | + end | |
69 | + | |
70 | + # Never trust parameters from the scary internet, only allow the white list through. | |
71 | + def project_params | |
72 | + params[:project] | |
73 | + end | |
74 | + | |
75 | +end | ... | ... |
... | ... | @@ -0,0 +1,76 @@ |
1 | +class RepositoriesController < ApplicationController | |
2 | + before_action :set_repository, only: [:show, :edit, :update, :destroy] | |
3 | + | |
4 | + # GET /repositories | |
5 | + # GET /repositories.json | |
6 | + def index | |
7 | + @project = Project.find(params[:project_id]) | |
8 | + @repositories = Repository.repositories_of(params[:project_id]) | |
9 | + end | |
10 | + | |
11 | + # GET /repositories/1 | |
12 | + # GET /repositories/1.json | |
13 | + def show | |
14 | + end | |
15 | + | |
16 | + # GET /repositories/new | |
17 | + def new | |
18 | + @repository = Repository.new | |
19 | + @project = Project.find(params[:project_id]) | |
20 | + end | |
21 | + | |
22 | + # GET /repositories/1/edit | |
23 | + def edit | |
24 | + end | |
25 | + | |
26 | + # POST /repositories | |
27 | + # POST /repositories.json | |
28 | + def create | |
29 | + @repository = Repository.new(repository_params) | |
30 | + | |
31 | + respond_to do |format| | |
32 | + if @repository.save | |
33 | + format.html { redirect_to @repository, notice: 'Repository was successfully created.' } | |
34 | + format.json { render action: 'show', status: :created, location: @repository } | |
35 | + else | |
36 | + format.html { render action: 'new' } | |
37 | + format.json { render json: @repository.errors, status: :unprocessable_entity } | |
38 | + end | |
39 | + end | |
40 | + end | |
41 | + | |
42 | + # PATCH/PUT /repositories/1 | |
43 | + # PATCH/PUT /repositories/1.json | |
44 | + def update | |
45 | + respond_to do |format| | |
46 | + if @repository.update(repository_params) | |
47 | + format.html { redirect_to @repository, notice: 'Repository was successfully updated.' } | |
48 | + format.json { head :no_content } | |
49 | + else | |
50 | + format.html { render action: 'edit' } | |
51 | + format.json { render json: @repository.errors, status: :unprocessable_entity } | |
52 | + end | |
53 | + end | |
54 | + end | |
55 | + | |
56 | + # DELETE /repositories/1 | |
57 | + # DELETE /repositories/1.json | |
58 | + def destroy | |
59 | + @repository.destroy | |
60 | + respond_to do |format| | |
61 | + format.html { redirect_to repositories_url } | |
62 | + format.json { head :no_content } | |
63 | + end | |
64 | + end | |
65 | + | |
66 | + private | |
67 | + # Use callbacks to share common setup or constraints between actions. | |
68 | + def set_repository | |
69 | + @repository = Repository.find(params[:id]) | |
70 | + end | |
71 | + | |
72 | + # Never trust parameters from the scary internet, only allow the white list through. | |
73 | + def repository_params | |
74 | + params.require(:repository).permit(:name) | |
75 | + end | |
76 | +end | ... | ... |
... | ... | @@ -0,0 +1,76 @@ |
1 | +class RepositoriesController < ApplicationController | |
2 | + before_action :set_repository, only: [:show, :edit, :update, :destroy] | |
3 | + | |
4 | + # GET /repositories | |
5 | + # GET /repositories.json | |
6 | + def index | |
7 | + @project = Project.find(params[:project_id]) | |
8 | + @repositories = Repository.repositories_of(params[:project_id]) | |
9 | + end | |
10 | + | |
11 | + # GET /repositories/1 | |
12 | + # GET /repositories/1.json | |
13 | + def show | |
14 | + end | |
15 | + | |
16 | + # GET /repositories/new | |
17 | + def new | |
18 | + @repository = Repository.new | |
19 | + @project = Project.find(params[:id]) | |
20 | + end | |
21 | + | |
22 | + # GET /repositories/1/edit | |
23 | + def edit | |
24 | + end | |
25 | + | |
26 | + # POST /repositories | |
27 | + # POST /repositories.json | |
28 | + def create | |
29 | + @repository = Repository.new(repository_params) | |
30 | + | |
31 | + respond_to do |format| | |
32 | + if @repository.save | |
33 | + format.html { redirect_to @repository, notice: 'Repository was successfully created.' } | |
34 | + format.json { render action: 'show', status: :created, location: @repository } | |
35 | + else | |
36 | + format.html { render action: 'new' } | |
37 | + format.json { render json: @repository.errors, status: :unprocessable_entity } | |
38 | + end | |
39 | + end | |
40 | + end | |
41 | + | |
42 | + # PATCH/PUT /repositories/1 | |
43 | + # PATCH/PUT /repositories/1.json | |
44 | + def update | |
45 | + respond_to do |format| | |
46 | + if @repository.update(repository_params) | |
47 | + format.html { redirect_to @repository, notice: 'Repository was successfully updated.' } | |
48 | + format.json { head :no_content } | |
49 | + else | |
50 | + format.html { render action: 'edit' } | |
51 | + format.json { render json: @repository.errors, status: :unprocessable_entity } | |
52 | + end | |
53 | + end | |
54 | + end | |
55 | + | |
56 | + # DELETE /repositories/1 | |
57 | + # DELETE /repositories/1.json | |
58 | + def destroy | |
59 | + @repository.destroy | |
60 | + respond_to do |format| | |
61 | + format.html { redirect_to repositories_url } | |
62 | + format.json { head :no_content } | |
63 | + end | |
64 | + end | |
65 | + | |
66 | + private | |
67 | + # Use callbacks to share common setup or constraints between actions. | |
68 | + def set_repository | |
69 | + @repository = Repository.find(params[:id]) | |
70 | + end | |
71 | + | |
72 | + # Never trust parameters from the scary internet, only allow the white list through. | |
73 | + def repository_params | |
74 | + params.require(:repository).permit(:name) | |
75 | + end | |
76 | +end | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +class Repository < KalibroEntities::Entities::Repository | |
2 | + | |
3 | + include ActiveModel::Validations | |
4 | + include ActiveModel::Conversion | |
5 | + extend ActiveModel::Naming | |
6 | + delegate :url_helpers, to: 'Rails.application.routes' | |
7 | + | |
8 | + def persisted? | |
9 | + Project.exists?(self.id) unless self.id.nil? | |
10 | + end | |
11 | + | |
12 | + def update(attributes = {}) | |
13 | + attributes.each { |field, value| send("#{field}=", value) if self.class.is_valid?(field) } | |
14 | + self.save | |
15 | + end | |
16 | + | |
17 | +end | ... | ... |
app/views/projects/index.html.erb
... | ... | @@ -0,0 +1,26 @@ |
1 | +<h1>Listing Projects</h1> | |
2 | + | |
3 | +<table> | |
4 | + <thead> | |
5 | + <tr> | |
6 | + <th>Name</th> | |
7 | + <th>Description</th> | |
8 | + <th></th> | |
9 | + </tr> | |
10 | + </thead> | |
11 | + | |
12 | + <tbody> | |
13 | + <% @projects.each do |project| %> | |
14 | + <tr> | |
15 | + <td><%= project.name %></td> | |
16 | + <td><%= project.description %></td> | |
17 | + <td><%= link_to 'Show', project_path(project.id) %></td> | |
18 | + <td><%= link_to 'Edit', edit_project_path(project.id) %></td> | |
19 | + </tr> | |
20 | + <% end %> | |
21 | + </tbody> | |
22 | +</table> | |
23 | + | |
24 | +<br> | |
25 | + | |
26 | +<%= link_to 'New Project', new_project_path %> | ... | ... |
app/views/projects/show.html.erb
... | ... | @@ -8,6 +8,28 @@ |
8 | 8 | <%= @project.description %> |
9 | 9 | </p> |
10 | 10 | |
11 | +<h2>Repositories</h2> | |
12 | + | |
13 | +<%= link_to 'New Repository', new_project_repository_path(@project)%> | |
14 | + | |
15 | +<table border="1" width="30%"> | |
16 | + <thead> | |
17 | + <tr> | |
18 | + <th>Name</th> | |
19 | + <th>Type</th> | |
20 | + </tr> | |
21 | + </thead> | |
22 | + | |
23 | + <tbody> | |
24 | + <% @project_repositories.each do |repository| %> | |
25 | + <tr> | |
26 | + <td align="center"><%= repository.name %></td> | |
27 | + <td align="center"><%= repository.type %></td> | |
28 | + </tr> | |
29 | + <% end %> | |
30 | + </tbody> | |
31 | +</table> | |
32 | + | |
11 | 33 | <p> |
12 | 34 | <% if project_owner? @project.id %> |
13 | 35 | <%= link_to 'Destroy', project_path(@project.id), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %> | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +<p> | |
2 | + <strong>Name:</strong> | |
3 | + <%= @project.name %> | |
4 | +</p> | |
5 | + | |
6 | +<p> | |
7 | + <strong>Description:</strong> | |
8 | + <%= @project.description %> | |
9 | +</p> | |
10 | + | |
11 | +<h2>Repositories</h2> | |
12 | + | |
13 | +<%= link_to 'New Repository', new_project_repository_path(@project_id)%> | |
14 | + | |
15 | +<table border="1" width="30%"> | |
16 | + <thead> | |
17 | + <tr> | |
18 | + <th>Name</th> | |
19 | + <th>Type</th> | |
20 | + </tr> | |
21 | + </thead> | |
22 | + | |
23 | + <tbody> | |
24 | + <% @project_repositories.each do |repository| %> | |
25 | + <tr> | |
26 | + <td align="center"><%= repository.name %></td> | |
27 | + <td align="center"><%= repository.type %></td> | |
28 | + </tr> | |
29 | + <% end %> | |
30 | + </tbody> | |
31 | +</table> | |
32 | + | |
33 | +<p> | |
34 | + <%= link_to 'Destroy', project_path(@project.id), method: :delete, data: { confirm: 'Are you sure?' } %> | |
35 | +</p> | |
36 | + | |
37 | +<%= link_to 'Back', projects_path %> | ... | ... |
... | ... | @@ -0,0 +1,36 @@ |
1 | +<%= form_for(@repository) do |f| %> | |
2 | + <% if @repository.errors.any? %> | |
3 | + <div id="error_explanation"> | |
4 | + <h2><%= pluralize(@repository.errors.count, "error") %> prohibited this repository from being saved:</h2> | |
5 | + | |
6 | + <ul> | |
7 | + <% @repository.errors.full_messages.each do |msg| %> | |
8 | + <li><%= msg %></li> | |
9 | + <% end %> | |
10 | + </ul> | |
11 | + </div> | |
12 | + <% end %> | |
13 | + | |
14 | + <div class="field"> | |
15 | + <%= f.label :name %><br> | |
16 | + <%= f.text_field :name %> | |
17 | + </div> | |
18 | + | |
19 | + <div class="field"> | |
20 | + <%= f.label :type %><br> | |
21 | + <%= f.text_field :type %> | |
22 | + </div> | |
23 | + | |
24 | + <div class="field"> | |
25 | + <%= f.label :addres %><br> | |
26 | + <%= f.text_field :address %> | |
27 | + </div> | |
28 | + | |
29 | + <div class="field"> | |
30 | + <%= f.label :configuration %><br> | |
31 | + <%= f.text_field :configuration_id %> | |
32 | + </div> | |
33 | + <div class="actions"> | |
34 | + <%= f.submit %> | |
35 | + </div> | |
36 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,36 @@ |
1 | +<%= form_for(@repository) do |f| %> | |
2 | + <% if @repository.errors.any? %> | |
3 | + <div id="error_explanation"> | |
4 | + <h2><%= pluralize(@repository.errors.count, "error") %> prohibited this repository from being saved:</h2> | |
5 | + | |
6 | + <ul> | |
7 | + <% @repository.errors.full_messages.each do |msg| %> | |
8 | + <li><%= msg %></li> | |
9 | + <% end %> | |
10 | + </ul> | |
11 | + </div> | |
12 | + <% end %> | |
13 | + | |
14 | + <div class="field"> | |
15 | + <%= f.label :name %><br> | |
16 | + <%= f.text_field :name %> | |
17 | + </div> | |
18 | + | |
19 | + <div class="field"> | |
20 | + <%= f.label :type %><br> | |
21 | + <%= f.text_field :type %> | |
22 | + </div> | |
23 | + | |
24 | + <div class="field"> | |
25 | + <%= f.label :addres %><br> | |
26 | + <%= f.text_field :address %> | |
27 | + </div> | |
28 | + | |
29 | + <div class="field"> | |
30 | + <%= f.label :configuration %><br> | |
31 | + <%= f.text_field :configuration %> | |
32 | + </div> | |
33 | + <div class="actions"> | |
34 | + <%= f.submit %> | |
35 | + </div> | |
36 | +<% end %> | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +<h1>Listing repositories</h1> | |
2 | + | |
3 | +<table> | |
4 | + <thead> | |
5 | + <tr> | |
6 | + <th>Name</th> | |
7 | + <th></th> | |
8 | + <th></th> | |
9 | + <th></th> | |
10 | + </tr> | |
11 | + </thead> | |
12 | + | |
13 | + <tbody> | |
14 | + <% @repositories.each do |repository| %> | |
15 | + <tr> | |
16 | + <td><%= repository.name %></td> | |
17 | + <td><%= link_to 'Show', repository %></td> | |
18 | + <td><%= link_to 'Edit', edit_repository_path(repository) %></td> | |
19 | + <td><%= link_to 'Destroy', repository, method: :delete, data: { confirm: 'Are you sure?' } %></td> | |
20 | + </tr> | |
21 | + <% end %> | |
22 | + </tbody> | |
23 | +</table> | |
24 | + | |
25 | +<br> | |
26 | + | |
27 | +<%= link_to 'New Repository', new_project_repository_path(@project) %> | ... | ... |
... | ... | @@ -0,0 +1,27 @@ |
1 | +<h1>Listing repositories</h1> | |
2 | + | |
3 | +<table> | |
4 | + <thead> | |
5 | + <tr> | |
6 | + <th>Name</th> | |
7 | + <th></th> | |
8 | + <th></th> | |
9 | + <th></th> | |
10 | + </tr> | |
11 | + </thead> | |
12 | + | |
13 | + <tbody> | |
14 | + <% @repositories.each do |repository| %> | |
15 | + <tr> | |
16 | + <td><%= repository.name %></td> | |
17 | + <td><%= link_to 'Show', repository %></td> | |
18 | + <td><%= link_to 'Edit', edit_repository_path(repository) %></td> | |
19 | + <td><%= link_to 'Destroy', repository, method: :delete, data: { confirm: 'Are you sure?' } %></td> | |
20 | + </tr> | |
21 | + <% end %> | |
22 | + </tbody> | |
23 | +</table> | |
24 | + | |
25 | +<br> | |
26 | + | |
27 | +<%= link_to 'New Repository', new_repository_path %> | ... | ... |
... | ... | @@ -0,0 +1 @@ |
1 | +json.extract! @repository, :name, :created_at, :updated_at | ... | ... |
... | ... | @@ -0,0 +1,41 @@ |
1 | + development: | |
2 | + adapter: sqlite3 | |
3 | + database: db/development.sqlite3 | |
4 | + pool: 5 | |
5 | + timeout: 5000 | |
6 | + | |
7 | +#development: | |
8 | +# adapter: postgresql | |
9 | +# host: localhost | |
10 | +# encoding: utf8 | |
11 | +# database: mezuro | |
12 | +# username: mezuro | |
13 | +# password: mezuro | |
14 | + | |
15 | + test: | |
16 | + adapter: sqlite3 | |
17 | + database: db/test.sqlite3 | |
18 | + pool: 5 | |
19 | + timeout: 5000 | |
20 | + | |
21 | +# test: | |
22 | +# adapter: postgresql | |
23 | +# host: localhost | |
24 | +# encoding: utf8 | |
25 | +# database: mezuro | |
26 | +# username: mezuro | |
27 | +# password: mezuro | |
28 | + | |
29 | +production: | |
30 | + adapter: sqlite3 | |
31 | + database: db/production.sqlite3 | |
32 | + pool: 5 | |
33 | + timeout: 5000 | |
34 | + | |
35 | +#production: | |
36 | +# adapter: postgresql | |
37 | +# host: localhost | |
38 | +# encoding: utf8 | |
39 | +# database: mezuro | |
40 | +# username: mezuro | |
41 | +# password: mezuro | ... | ... |
config/routes.rb
1 | 1 | Mezuro::Application.routes.draw do |
2 | + #resources :repositories | |
3 | + | |
2 | 4 | devise_for :users |
3 | 5 | |
4 | 6 | root "home#index" |
5 | - resources :projects | |
7 | + #resources :projects | |
8 | + | |
9 | + resources :projects do | |
10 | + resources :repositories | |
11 | + end | |
6 | 12 | # The priority is based upon order of creation: first created -> highest priority. |
7 | 13 | # See how all your routes lay out with "rake routes". |
8 | 14 | ... | ... |
... | ... | @@ -0,0 +1,62 @@ |
1 | +Mezuro::Application.routes.draw do | |
2 | + resources :repositories | |
3 | + | |
4 | + devise_for :users | |
5 | + | |
6 | + root "home#index" | |
7 | + resources :projects | |
8 | + # The priority is based upon order of creation: first created -> highest priority. | |
9 | + # See how all your routes lay out with "rake routes". | |
10 | + | |
11 | + # You can have the root of your site routed with "root" | |
12 | + # root 'welcome#index' | |
13 | + | |
14 | + # Example of regular route: | |
15 | + # get 'products/:id' => 'catalog#view' | |
16 | + | |
17 | + # Example of named route that can be invoked with purchase_url(id: product.id) | |
18 | + # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase | |
19 | + | |
20 | + # Example resource route (maps HTTP verbs to controller actions automatically): | |
21 | + # resources :products | |
22 | + | |
23 | + # Example resource route with options: | |
24 | + # resources :products do | |
25 | + # member do | |
26 | + # get 'short' | |
27 | + # post 'toggle' | |
28 | + # end | |
29 | + # | |
30 | + # collection do | |
31 | + # get 'sold' | |
32 | + # end | |
33 | + # end | |
34 | + | |
35 | + # Example resource route with sub-resources: | |
36 | + # resources :products do | |
37 | + # resources :comments, :sales | |
38 | + # resource :seller | |
39 | + # end | |
40 | + | |
41 | + # Example resource route with more complex sub-resources: | |
42 | + # resources :products do | |
43 | + # resources :comments | |
44 | + # resources :sales do | |
45 | + # get 'recent', on: :collection | |
46 | + # end | |
47 | + # end | |
48 | + | |
49 | + # Example resource route with concerns: | |
50 | + # concern :toggleable do | |
51 | + # post 'toggle' | |
52 | + # end | |
53 | + # resources :posts, concerns: :toggleable | |
54 | + # resources :photos, concerns: :toggleable | |
55 | + | |
56 | + # Example resource route within a namespace: | |
57 | + # namespace :admin do | |
58 | + # # Directs /admin/products/* to Admin::ProductsController | |
59 | + # # (app/controllers/admin/products_controller.rb) | |
60 | + # resources :products | |
61 | + # end | |
62 | +end | ... | ... |
db/schema.rb
... | ... | @@ -16,9 +16,12 @@ ActiveRecord::Schema.define(version: 20130826211404) do |
16 | 16 | create_table "project_ownerships", force: true do |t| |
17 | 17 | t.integer "user_id" |
18 | 18 | t.integer "project_id" |
19 | + | |
20 | + create_table "repositories", force: true do |t| | |
21 | + t.string "name" | |
19 | 22 | t.datetime "created_at" |
20 | 23 | t.datetime "updated_at" |
21 | - end | |
24 | + | |
22 | 25 | |
23 | 26 | create_table "users", force: true do |t| |
24 | 27 | t.string "name", default: "", null: false | ... | ... |
... | ... | @@ -0,0 +1,160 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +# This spec was generated by rspec-rails when you ran the scaffold generator. | |
4 | +# It demonstrates how one might use RSpec to specify the controller code that | |
5 | +# was generated by Rails when you ran the scaffold generator. | |
6 | +# | |
7 | +# It assumes that the implementation code is generated by the rails scaffold | |
8 | +# generator. If you are using any extension libraries to generate different | |
9 | +# controller code, this generated spec may or may not pass. | |
10 | +# | |
11 | +# It only uses APIs available in rails and/or rspec-rails. There are a number | |
12 | +# of tools you can use to make these specs even more expressive, but we're | |
13 | +# sticking to rails and rspec-rails APIs to keep things simple and stable. | |
14 | +# | |
15 | +# Compared to earlier versions of this generator, there is very limited use of | |
16 | +# stubs and message expectations in this spec. Stubs are only used when there | |
17 | +# is no simpler way to get a handle on the object needed for the example. | |
18 | +# Message expectations are only used when there is no simpler way to specify | |
19 | +# that an instance is receiving a specific message. | |
20 | + | |
21 | +describe RepositoriesController do | |
22 | + | |
23 | + # This should return the minimal set of attributes required to create a valid | |
24 | + # Repository. As you add validations to Repository, be sure to | |
25 | + # adjust the attributes here as well. | |
26 | + let(:valid_attributes) { { "name" => "MyString" } } | |
27 | + | |
28 | + # This should return the minimal set of values that should be in the session | |
29 | + # in order to pass any filters (e.g. authentication) defined in | |
30 | + # RepositoriesController. Be sure to keep this updated too. | |
31 | + let(:valid_session) { {} } | |
32 | + | |
33 | + describe "GET index" do | |
34 | + it "assigns all repositories as @repositories" do | |
35 | + repository = Repository.create! valid_attributes | |
36 | + get :index, {}, valid_session | |
37 | + assigns(:repositories).should eq([repository]) | |
38 | + end | |
39 | + end | |
40 | + | |
41 | + describe "GET show" do | |
42 | + it "assigns the requested repository as @repository" do | |
43 | + repository = Repository.create! valid_attributes | |
44 | + get :show, {:id => repository.to_param}, valid_session | |
45 | + assigns(:repository).should eq(repository) | |
46 | + end | |
47 | + end | |
48 | + | |
49 | + describe "GET new" do | |
50 | + it "assigns a new repository as @repository" do | |
51 | + get :new, {}, valid_session | |
52 | + assigns(:repository).should be_a_new(Repository) | |
53 | + end | |
54 | + end | |
55 | + | |
56 | + describe "GET edit" do | |
57 | + it "assigns the requested repository as @repository" do | |
58 | + repository = Repository.create! valid_attributes | |
59 | + get :edit, {:id => repository.to_param}, valid_session | |
60 | + assigns(:repository).should eq(repository) | |
61 | + end | |
62 | + end | |
63 | + | |
64 | + describe "POST create" do | |
65 | + describe "with valid params" do | |
66 | + it "creates a new Repository" do | |
67 | + expect { | |
68 | + post :create, {:repository => valid_attributes}, valid_session | |
69 | + }.to change(Repository, :count).by(1) | |
70 | + end | |
71 | + | |
72 | + it "assigns a newly created repository as @repository" do | |
73 | + post :create, {:repository => valid_attributes}, valid_session | |
74 | + assigns(:repository).should be_a(Repository) | |
75 | + assigns(:repository).should be_persisted | |
76 | + end | |
77 | + | |
78 | + it "redirects to the created repository" do | |
79 | + post :create, {:repository => valid_attributes}, valid_session | |
80 | + response.should redirect_to(Repository.last) | |
81 | + end | |
82 | + end | |
83 | + | |
84 | + describe "with invalid params" do | |
85 | + it "assigns a newly created but unsaved repository as @repository" do | |
86 | + # Trigger the behavior that occurs when invalid params are submitted | |
87 | + Repository.any_instance.stub(:save).and_return(false) | |
88 | + post :create, {:repository => { "name" => "invalid value" }}, valid_session | |
89 | + assigns(:repository).should be_a_new(Repository) | |
90 | + end | |
91 | + | |
92 | + it "re-renders the 'new' template" do | |
93 | + # Trigger the behavior that occurs when invalid params are submitted | |
94 | + Repository.any_instance.stub(:save).and_return(false) | |
95 | + post :create, {:repository => { "name" => "invalid value" }}, valid_session | |
96 | + response.should render_template("new") | |
97 | + end | |
98 | + end | |
99 | + end | |
100 | + | |
101 | + describe "PUT update" do | |
102 | + describe "with valid params" do | |
103 | + it "updates the requested repository" do | |
104 | + repository = Repository.create! valid_attributes | |
105 | + # Assuming there are no other repositories in the database, this | |
106 | + # specifies that the Repository created on the previous line | |
107 | + # receives the :update_attributes message with whatever params are | |
108 | + # submitted in the request. | |
109 | + Repository.any_instance.should_receive(:update).with({ "name" => "MyString" }) | |
110 | + put :update, {:id => repository.to_param, :repository => { "name" => "MyString" }}, valid_session | |
111 | + end | |
112 | + | |
113 | + it "assigns the requested repository as @repository" do | |
114 | + repository = Repository.create! valid_attributes | |
115 | + put :update, {:id => repository.to_param, :repository => valid_attributes}, valid_session | |
116 | + assigns(:repository).should eq(repository) | |
117 | + end | |
118 | + | |
119 | + it "redirects to the repository" do | |
120 | + repository = Repository.create! valid_attributes | |
121 | + put :update, {:id => repository.to_param, :repository => valid_attributes}, valid_session | |
122 | + response.should redirect_to(repository) | |
123 | + end | |
124 | + end | |
125 | + | |
126 | + describe "with invalid params" do | |
127 | + it "assigns the repository as @repository" do | |
128 | + repository = Repository.create! valid_attributes | |
129 | + # Trigger the behavior that occurs when invalid params are submitted | |
130 | + Repository.any_instance.stub(:save).and_return(false) | |
131 | + put :update, {:id => repository.to_param, :repository => { "name" => "invalid value" }}, valid_session | |
132 | + assigns(:repository).should eq(repository) | |
133 | + end | |
134 | + | |
135 | + it "re-renders the 'edit' template" do | |
136 | + repository = Repository.create! valid_attributes | |
137 | + # Trigger the behavior that occurs when invalid params are submitted | |
138 | + Repository.any_instance.stub(:save).and_return(false) | |
139 | + put :update, {:id => repository.to_param, :repository => { "name" => "invalid value" }}, valid_session | |
140 | + response.should render_template("edit") | |
141 | + end | |
142 | + end | |
143 | + end | |
144 | + | |
145 | + describe "DELETE destroy" do | |
146 | + it "destroys the requested repository" do | |
147 | + repository = Repository.create! valid_attributes | |
148 | + expect { | |
149 | + delete :destroy, {:id => repository.to_param}, valid_session | |
150 | + }.to change(Repository, :count).by(-1) | |
151 | + end | |
152 | + | |
153 | + it "redirects to the repositories list" do | |
154 | + repository = Repository.create! valid_attributes | |
155 | + delete :destroy, {:id => repository.to_param}, valid_session | |
156 | + response.should redirect_to(repositories_url) | |
157 | + end | |
158 | + end | |
159 | + | |
160 | +end | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +# Specs in this file have access to a helper object that includes | |
4 | +# the RepositoriesHelper. For example: | |
5 | +# | |
6 | +# describe RepositoriesHelper do | |
7 | +# describe "string concat" do | |
8 | +# it "concats two strings with spaces" do | |
9 | +# expect(helper.concat_strings("this","that")).to eq("this that") | |
10 | +# end | |
11 | +# end | |
12 | +# end | |
13 | +describe RepositoriesHelper do | |
14 | + pending "add some examples to (or delete) #{__FILE__}" | |
15 | +end | ... | ... |
... | ... | @@ -0,0 +1,11 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe "Repositories" do | |
4 | + describe "GET /repositories" do | |
5 | + it "works! (now write some real specs)" do | |
6 | + # Run the generator again with the --webrat flag if you want to use webrat methods/matchers | |
7 | + get repositories_path | |
8 | + response.status.should be(200) | |
9 | + end | |
10 | + end | |
11 | +end | ... | ... |
... | ... | @@ -0,0 +1,35 @@ |
1 | +require "spec_helper" | |
2 | + | |
3 | +describe RepositoriesController do | |
4 | + describe "routing" do | |
5 | + | |
6 | + it "routes to #index" do | |
7 | + get("/repositories").should route_to("repositories#index") | |
8 | + end | |
9 | + | |
10 | + it "routes to #new" do | |
11 | + get("/repositories/new").should route_to("repositories#new") | |
12 | + end | |
13 | + | |
14 | + it "routes to #show" do | |
15 | + get("/repositories/1").should route_to("repositories#show", :id => "1") | |
16 | + end | |
17 | + | |
18 | + it "routes to #edit" do | |
19 | + get("/repositories/1/edit").should route_to("repositories#edit", :id => "1") | |
20 | + end | |
21 | + | |
22 | + it "routes to #create" do | |
23 | + post("/repositories").should route_to("repositories#create") | |
24 | + end | |
25 | + | |
26 | + it "routes to #update" do | |
27 | + put("/repositories/1").should route_to("repositories#update", :id => "1") | |
28 | + end | |
29 | + | |
30 | + it "routes to #destroy" do | |
31 | + delete("/repositories/1").should route_to("repositories#destroy", :id => "1") | |
32 | + end | |
33 | + | |
34 | + end | |
35 | +end | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe "repositories/edit" do | |
4 | + before(:each) do | |
5 | + @repository = assign(:repository, stub_model(Repository, | |
6 | + :name => "MyString" | |
7 | + )) | |
8 | + end | |
9 | + | |
10 | + it "renders the edit repository form" do | |
11 | + render | |
12 | + | |
13 | + # Run the generator again with the --webrat flag if you want to use webrat matchers | |
14 | + assert_select "form[action=?][method=?]", repository_path(@repository), "post" do | |
15 | + assert_select "input#repository_name[name=?]", "repository[name]" | |
16 | + end | |
17 | + end | |
18 | +end | ... | ... |
... | ... | @@ -0,0 +1,20 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe "repositories/index" do | |
4 | + before(:each) do | |
5 | + assign(:repositories, [ | |
6 | + stub_model(Repository, | |
7 | + :name => "Name" | |
8 | + ), | |
9 | + stub_model(Repository, | |
10 | + :name => "Name" | |
11 | + ) | |
12 | + ]) | |
13 | + end | |
14 | + | |
15 | + it "renders a list of repositories" do | |
16 | + render | |
17 | + # Run the generator again with the --webrat flag if you want to use webrat matchers | |
18 | + assert_select "tr>td", :text => "Name".to_s, :count => 2 | |
19 | + end | |
20 | +end | ... | ... |
... | ... | @@ -0,0 +1,18 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe "repositories/new" do | |
4 | + before(:each) do | |
5 | + assign(:repository, stub_model(Repository, | |
6 | + :name => "MyString" | |
7 | + ).as_new_record) | |
8 | + end | |
9 | + | |
10 | + it "renders new repository form" do | |
11 | + render | |
12 | + | |
13 | + # Run the generator again with the --webrat flag if you want to use webrat matchers | |
14 | + assert_select "form[action=?][method=?]", repositories_path, "post" do | |
15 | + assert_select "input#repository_name[name=?]", "repository[name]" | |
16 | + end | |
17 | + end | |
18 | +end | ... | ... |
... | ... | @@ -0,0 +1,15 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe "repositories/show" do | |
4 | + before(:each) do | |
5 | + @repository = assign(:repository, stub_model(Repository, | |
6 | + :name => "Name" | |
7 | + )) | |
8 | + end | |
9 | + | |
10 | + it "renders attributes in <p>" do | |
11 | + render | |
12 | + # Run the generator again with the --webrat flag if you want to use webrat matchers | |
13 | + rendered.should match(/Name/) | |
14 | + end | |
15 | +end | ... | ... |