Commit 7815bba39a668709ab38b81819a719f7e2f337de

Authored by Rafael Manzo
1 parent 4187ef90

Renamed ProjectImage image_url to url

app/controllers/projects_controller.rb
... ... @@ -23,7 +23,7 @@ class ProjectsController < ApplicationController
23 23 @project = Project.new(project_params)
24 24 respond_to do |format|
25 25 create_and_redir(format)
26   - ProjectImage.create(image_url: project_params[:image_url],project_id: @project.id )
  26 + ProjectImage.create(url: project_params[:url],project_id: @project.id )
27 27 end
28 28 end
29 29  
... ... @@ -46,7 +46,7 @@ class ProjectsController < ApplicationController
46 46 def update
47 47 set_project
48 48 @project_image = ProjectImage.find_by_project_id(@project.id)
49   - if @project.update(project_params) && @project_image.update(image_url: project_params[:image_url])
  49 + if @project.update(project_params) && @project_image.update(url: project_params[:image_url])
50 50 redirect_to(project_path(@project.id))
51 51 else
52 52 render "edit"
... ...
app/models/project.rb
... ... @@ -3,7 +3,7 @@ require "validators/kalibro_uniqueness_validator.rb"
3 3 class Project < KalibroGatekeeperClient::Entities::Project
4 4 include KalibroRecord
5 5  
6   - attr_accessor :name,:image_url
  6 + attr_accessor :name
7 7 validates :name, presence: true, kalibro_uniqueness: true
8 8  
9 9 def repositories
... ...
app/views/projects/_form.html.erb
... ... @@ -17,7 +17,7 @@
17 17 <div class="form-row">
18 18 <div class="field-container">
19 19 <%= f.label "Image url", class: 'control-label' %><br>
20   - <%= f.text_field :image_url, class: 'text-area' ,value: @project_image.nil? ? '#' : @project_image.image_url %>
  20 + <%= f.text_field :image_url, class: 'text-area' ,value: @project_image.nil? ? '#' : @project_image.url %>
21 21 </div>
22 22 </div>
23 23 </div>
... ...
app/views/projects/show.html.erb
... ... @@ -2,8 +2,8 @@
2 2 <div class="page-header">
3 3 <div class="row">
4 4 <div class="col-md-2">
5   - <% if @project_image && !@project_image.image_url.empty? %>
6   - <%= image_tag "#{@project_image.image_url}", size:"128x128" %>
  5 + <% if @project_image && !@project_image.url.empty? %>
  6 + <%= image_tag "#{@project_image.url}", size:"128x128" %>
7 7 <% else %>
8 8 <center><i class="fa fa-file-image-o fa-5x"></i></center><br />
9 9 No image available
... ...
db/migrate/20141119173020_rename_project_image_image_url_to_url.rb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +class RenameProjectImageImageUrlToUrl < ActiveRecord::Migration
  2 + def change
  3 + change_table :project_images do |t|
  4 + t.rename :image_url, :url
  5 + end
  6 + end
  7 +end
... ...
db/schema.rb
... ... @@ -11,7 +11,7 @@
11 11 #
12 12 # It's strongly recommended that you check this file into your version control system.
13 13  
14   -ActiveRecord::Schema.define(version: 20141006232631) do
  14 +ActiveRecord::Schema.define(version: 20141119173020) do
15 15  
16 16 create_table "mezuro_configuration_ownerships", force: true do |t|
17 17 t.integer "user_id"
... ... @@ -22,7 +22,7 @@ ActiveRecord::Schema.define(version: 20141006232631) do
22 22  
23 23 create_table "project_images", force: true do |t|
24 24 t.integer "project_id"
25   - t.string "image_url"
  25 + t.string "url"
26 26 t.datetime "created_at"
27 27 t.datetime "updated_at"
28 28 end
... ...
spec/factories/project_images.rb
... ... @@ -3,10 +3,10 @@
3 3 FactoryGirl.define do
4 4 factory :project_image do
5 5 project_id 1
6   - image_url "Example"
  6 + url "Example"
7 7 end
8 8  
9 9 factory :project_no_image, class: ProjectImage do
10   - image_url nil
  10 + url nil
11 11 end
12 12 end
... ...
spec/factories/projects.rb
... ... @@ -5,7 +5,6 @@ FactoryGirl.define do
5 5 id 1
6 6 name "QT Calculator"
7 7 description "A simple calculator for us."
8   - image_url { FactoryGirl.build(:project_image) }
9 8 end
10 9  
11 10 factory :another_project, class: Project do
... ...
spec/models/project_image_spec.rb
... ... @@ -3,23 +3,5 @@ require &#39;rails_helper&#39;
3 3 RSpec.describe ProjectImage, :type => :model do
4 4 describe 'associations' do
5 5 it { is_expected.to belong_to(:project) }
6   - it { should belong_to(:project) }
7   - end
8   -
9   - describe 'methods' do
10   -
11   - it 'should validate url blank' do
12   - @project_no_image = FactoryGirl.create(:project_no_image)
13   - expect(@project_no_image.image_url).to eq("no-image-available.png")
14   - end
15   -
16   - it "Can be assigns" do
17   - expect(ProjectImage.new).to be_an_instance_of(ProjectImage)
18   - end
19   -
20   - it 'should validate url field' do
21   - @project_no_image = FactoryGirl.create(:project_no_image)
22   - expect(@project_no_image.check_no_image).to eq("")
23   - end
24 6 end
25 7 end
... ...