summaryrefslogtreecommitdiff
path: root/spec/requests/admin/admin_projects_spec.rb
blob: 8aa311e84427524a2aa28a13a28e32e3a49c7880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
require 'spec_helper'

describe "Admin::Projects" do
  before do 
    @project = Factory :project,
      :name => "LeGiT",
      :code => "LGT"
    login_as :admin
  end

  describe "GET /admin/projects" do
    before do 
      visit admin_projects_path
    end

    it "should be ok" do
      current_path.should == admin_projects_path
    end

    it "should have projects list" do 
      page.should have_content(@project.code)
      page.should have_content(@project.name)
    end
  end

  describe "GET /admin/projects/:id" do 
    before do 
      visit admin_projects_path
      click_link "Show"
    end

    it "should have project info" do 
      page.should have_content(@project.code)
      page.should have_content(@project.name)
    end
  end

  describe "GET /admin/projects/:id/edit" do 
    before do 
      visit admin_projects_path
      click_link "edit_project_#{@project.id}"
    end

    it "should have project edit page" do 
      page.should have_content("Name")
      page.should have_content("Code")
    end

    describe "Update project" do
      before do 
        fill_in "project_name", :with => "Big Bang"
        fill_in "project_code", :with => "BB1"
        click_button "Save"
        @project.reload
      end

      it "should show page with  new data" do 
        page.should have_content("BB1")
        page.should have_content("Big Bang")
      end

      it "should change project entry" do 
        @project.name.should == "Big Bang"
        @project.code.should == "BB1"
      end
    end
  end

  describe "GET /admin/projects/new" do
    before do 
      visit admin_projects_path
      click_link "New Project"
    end

    it "should be correct path" do
      current_path.should == new_admin_project_path 
    end

    it "should have labels for new project" do
      page.should have_content("Name") 
      page.should have_content("Path") 
      page.should have_content("Description") 
    end
  end

  describe "POST /admin/projects" do
    before do 
      visit new_admin_project_path
      fill_in 'Name', :with => 'NewProject'
      fill_in 'Code', :with => 'NPR'
      fill_in 'Path', :with => '/tmp/legit_test/legit'
      expect { click_button "Save" }.to change { Project.count }.by(1)
      @project = Project.last
    end

    it "should be correct path" do
      current_path.should == admin_project_path(@project)
    end

    it "should show project" do
      page.should have_content(@project.name)
      page.should have_content(@project.path)
      page.should have_content(@project.description)
    end
  end
end